Title: [283743] trunk/Tools
Revision
283743
Author
jbed...@apple.com
Date
2021-10-07 14:22:39 -0700 (Thu, 07 Oct 2021)

Log Message

[WebKitBot] Land local changes on production host
https://bugs.webkit.org/show_bug.cgi?id=231388
<rdar://problem/83996428>

Reviewed by Yusuke Suzuki.

* WebKitBot/src/Commit.mjs: Add Slack ID integration.
* WebKitBot/src/Contributors.mjs: Ditto.
* WebKitBot/src/Utility.mjs:
* WebKitBot/src/WebKitBot.mjs: Add "hi" and "yt" commands.
* WebKitBot/src/index.mjs:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (283742 => 283743)


--- trunk/Tools/ChangeLog	2021-10-07 21:08:11 UTC (rev 283742)
+++ trunk/Tools/ChangeLog	2021-10-07 21:22:39 UTC (rev 283743)
@@ -1,3 +1,17 @@
+2021-10-07  Jonathan Bedard  <jbed...@apple.com>
+
+        [WebKitBot] Land local changes on production host
+        https://bugs.webkit.org/show_bug.cgi?id=231388
+        <rdar://problem/83996428>
+
+        Reviewed by Yusuke Suzuki.
+
+        * WebKitBot/src/Commit.mjs: Add Slack ID integration.
+        * WebKitBot/src/Contributors.mjs: Ditto.
+        * WebKitBot/src/Utility.mjs:
+        * WebKitBot/src/WebKitBot.mjs: Add "hi" and "yt" commands.
+        * WebKitBot/src/index.mjs: 
+
 2021-10-07  Michael Catanzaro  <mcatanz...@gnome.org>
 
         Misc compiler warning fixes, October 2021

Modified: trunk/Tools/WebKitBot/src/Commit.mjs (283742 => 283743)


--- trunk/Tools/WebKitBot/src/Commit.mjs	2021-10-07 21:08:11 UTC (rev 283742)
+++ trunk/Tools/WebKitBot/src/Commit.mjs	2021-10-07 21:22:39 UTC (rev 283743)
@@ -78,8 +78,12 @@
             this._author = this._email;
             if (this._email) {
                 let entry = contributors.queryWithEmail(this._email);
-                if (entry && entry.nicks && entry.nicks[0])
-                    this._author = `${entry.name} (@${entry.nicks[0]})`;
+                if (entry) {
+                    if (entry.nicks && entry.nicks[0])
+                        this._author = `${entry.name} (@${entry.nicks[0]})`;
+                    if (entry.slackId)
+                        this._authorSlackId = entry.slackId;
+                }
             }
         }
         if (this._revert) {
@@ -107,6 +111,7 @@
     get radar() { return this._radar; }
     get title() { return this._title; }
     get author() { return this._author; }
+    get authorSlackId() { return this._authorSlackId; }
     get url() { return this._url; }
 
     message()
@@ -113,7 +118,10 @@
     {
         let results = [];
         results.push(escapeForSlackText(`${this._title}`));
-        results.push(escapeForSlackText(`${this._url} by ${this._author}`));
+        if (!this._authorSlackId)
+            results.push(escapeForSlackText(`${this._url} by ${this._author}`));
+        else
+            results.push(`${escapeForSlackText(this._url)} by <@${this._authorSlackId}>`);
         let urls = [];
         if (this._bugzilla !== null)
             urls.push(escapeForSlackText(`https://webkit.org/b/${this._bugzilla}`));

Modified: trunk/Tools/WebKitBot/src/Contributors.mjs (283742 => 283743)


--- trunk/Tools/WebKitBot/src/Contributors.mjs	2021-10-07 21:08:11 UTC (rev 283742)
+++ trunk/Tools/WebKitBot/src/Contributors.mjs	2021-10-07 21:22:39 UTC (rev 283743)
@@ -49,4 +49,13 @@
     {
         return this.emails.get(email);
     }
+
+    queryWithSlackId(slackId)
+    {
+        for (let entry of this.emails.values()) {
+            if (entry.slackId === slackId)
+                return entry;
+        }
+        return null;
+    }
 }

Modified: trunk/Tools/WebKitBot/src/Utility.mjs (283742 => 283743)


--- trunk/Tools/WebKitBot/src/Utility.mjs	2021-10-07 21:08:11 UTC (rev 283742)
+++ trunk/Tools/WebKitBot/src/Utility.mjs	2021-10-07 21:22:39 UTC (rev 283743)
@@ -31,11 +31,9 @@
     return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
 }
 
-const DEBUG = false;
-
 export function dataLogLn(message)
 {
-    if (DEBUG)
+    if (process.env.DEBUG)
         console.log(message);
 }
 

Modified: trunk/Tools/WebKitBot/src/WebKitBot.mjs (283742 => 283743)


--- trunk/Tools/WebKitBot/src/WebKitBot.mjs	2021-10-07 21:08:11 UTC (rev 283742)
+++ trunk/Tools/WebKitBot/src/WebKitBot.mjs	2021-10-07 21:22:39 UTC (rev 283743)
@@ -23,6 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import {stat} from "fs";
 import path from "path";
 import util from "util";
 import {execFile, spawn} from "child_process";
@@ -30,12 +31,12 @@
 import AsyncTaskQueue from "./AsyncTaskQueue.mjs";
 import {dataLogLn, escapeForSlackText, isASCII, rootDirectoryOfWebKit} from "./Utility.mjs";
 
-const webkitPatchPath = path.resolve(rootDirectoryOfWebKit(), "Tools", "Scripts", "webkit-patch");
 const defaultTaskLimit = 10;
 const defaultPullPeriod = 60 * 1000 * 60;
 const defaultTimeoutForRevert = 60 * 1000 * 10;
 
 const execFileAsync = util.promisify(execFile);
+const statAsync = util.promisify(stat);
 
 function parseBugId(string)
 {
@@ -173,7 +174,18 @@
             usage: "`status`",
             operation: this.statusCommand.bind(this),
         });
+        this._commands.set("hi", {
+            description: "Responds with hi.",
+            usage: "`hi`",
+            operation: this.hiCommand.bind(this),
+        });
+        this._commands.set("yt?", {
+            description: "Responds with yes.",
+            usage: "`yt?`",
+            operation: this.youThereCommand.bind(this),
+        });
 
+
         this._rtm = new SlackRTMAPI.RTMClient(process.env.SLACK_TOKEN);
         this._rtm.on("message", async (event) => {
             if (event.type !== "message")
@@ -230,9 +242,54 @@
                 });
             } catch (error) {
                 console.error(error);
+                let stderr = error.stderr;
+                console.error("STDERR ", stderr);
+                if (typeof stderr === "string") {
+                    {
+                        let index = stderr.indexOf("Failed to apply reverse diff for revision");
+                        if (index !== -1) {
+                            let lines = stderr.slice(index).split("\n");
+                            lines.shift();
+                            let files = [];
+                            for (let line of lines) {
+                                try {
+                                    await statAsync(path.join(process.env.webkitWorkingDirectory, line));
+                                    files.push(line);
+                                } catch {
+                                    // THis is not a file.
+                                    break;
+                                }
+                            }
+                            if (files.length !== 0) {
+                                await this._web.chat.postMessage({
+                                    channel: event.channel,
+                                    text: `<@${event.user}> Failed to create revert patch because of the following conflicts:
+\`\`\`
+${escapeForSlackText(files.join("\n"))}\`\`\``,
+                                });
+                                return;
+                            }
+                        }
+                    }
+                    {
+                        let index = stderr.indexOf("You are not authorized to access bug");
+                        if (index !== -1) {
+                            let line = stderr.slice(index).split("\n")[0].trim();
+                            let matched = /#(\d+)/.match(line);
+                            await this._web.chat.postMessage({
+                                channel: event.channel,
+                                text: `<@${event.user}> Failed to create revert patch. Please ensure commit-qu...@webkit.org is authorized to access ${matched ? ("bug " + escapeForSlackText(matched[1])) : "the bug"}.`
+                            });
+                            return;
+                        }
+
+                    }
+                }
                 await this._web.chat.postMessage({
                     channel: event.channel,
-                    text: `<@${event.user}> Failed to create revert patch.`,
+                    text: `<@${event.user}> Failed to create revert patch.` + (stderr ? `
+\`\`\`
+${escapeForSlackText(stderr)}\`\`\`` : ""),
                 });
             }
             return;
@@ -326,10 +383,26 @@
     {
         await this._web.chat.postMessage({
             channel: event.channel,
-            text: `<@${event.user}> ${escapeForSlackText(this._taskQueue.length)} requests in queue.`,
+            text: `<@${event.user}> ${escapeForSlackText(String(this._taskQueue.length))} requests in queue.`,
         });
     }
 
+    async hiCommand(event, command, args)
+    {
+        await this._web.chat.postMessage({
+            channel: event.channel,
+            text: `Hi <@${event.user}>!`,
+        });
+    }
+
+    async youThereCommand(event, command, args)
+    {
+        await this._web.chat.postMessage({
+            channel: event.channel,
+            text: `<@${event.user}> yes`,
+        });
+    }
+
     async unknownCommand(event, command, args)
     {
         dataLogLn("Unknown command: ", command);
@@ -365,7 +438,7 @@
         await this.execInWebKitDirectorySimple("git", ["clean", "-df"]);
 
         dataLogLn("3. Pulling");
-        await this.execInWebKitDirectorySimple("git", ["pull", "origin", "master"]);
+        await this.execInWebKitDirectorySimple("git", ["pull"]);
 
         dataLogLn("4. Fetching");
         await this.execInWebKitDirectorySimple("git", ["svn", "fetch"]);
@@ -389,6 +462,7 @@
         dataLogLn("5. Creating revert patch ", revisions, reason);
         let results;
         try {
+            const webkitPatchPath = path.resolve("BotWebKit", "Tools", "Scripts", "webkit-patch");
             results = await execFileAsync(webkitPatchPath, [
                 "create-revert",
                 "--force-clean",
@@ -412,7 +486,9 @@
             });
         } catch (error) {
             dataLogLn(error);
-            throw new Error("Revert command failed");
+            let newError = new Error("Revert command failed");
+            newError.stderr = error.stderr;
+            throw newError;
         }
         let {stdout, stderr} = results;
         dataLogLn(stdout);

Modified: trunk/Tools/WebKitBot/src/index.mjs (283742 => 283743)


--- trunk/Tools/WebKitBot/src/index.mjs	2021-10-07 21:08:11 UTC (rev 283742)
+++ trunk/Tools/WebKitBot/src/index.mjs	2021-10-07 21:22:39 UTC (rev 283743)
@@ -25,7 +25,6 @@
 
 import dotenv from "dotenv";
 import storage from "node-persist";
-import WKR from "./WKR.mjs";
 import WebKitBot from "./WebKitBot.mjs";
 import SlackWebAPI from "@slack/web-api";
 
@@ -39,7 +38,6 @@
     let webClient = new SlackWebAPI.WebClient(process.env.SLACK_TOKEN);
     let auth = await webClient.auth.test();
 
-    WKR.main(webClient, auth);
     WebKitBot.main(webClient, auth);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to