You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2024/02/08 05:04:41 UTC
(superset) 01/01: feat(supersetbot): re-implement labeling bot as a GitHub action
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch supersetbot
in repository https://gitbox.apache.org/repos/asf/superset.git
commit af31502c17ddf0e713a4fdce0e5b657a199b92eb
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Wed Feb 7 21:04:22 2024 -0800
feat(supersetbot): re-implement labeling bot as a GitHub action
---
.github/workflows/supersetbot.js | 59 +++++++++++++++++++++++++++++++++++++++
.github/workflows/supersetbot.yml | 17 +++++++++++
2 files changed, 76 insertions(+)
diff --git a/.github/workflows/supersetbot.js b/.github/workflows/supersetbot.js
new file mode 100644
index 0000000000..8f841fb590
--- /dev/null
+++ b/.github/workflows/supersetbot.js
@@ -0,0 +1,59 @@
+const core = require('@actions/core');
+const github = require('@actions/github');
+
+function getActionFromComment(comment) {
+ return comment.split(/\s+/)[1];
+}
+
+function getArgFromComment(comment, argNumber) {
+ const parts = comment.match(/"[^"]+"|\S+/g).map(arg => arg.replace(/"/g, ''));
+ return parts[argNumber] || '';
+}
+
+async function run() {
+ try {
+ const token = process.env.GITHUB_TOKEN;
+ const commentBody = process.env.COMMENT_BODY.trim();
+ const octokit = github.getOctokit(token);
+ const { owner, repo } = github.context.repo;
+ const issue_number = github.context.issue.number;
+
+ // Check if comment contains command
+ if (!commentBody.includes("@supersetbot")) {
+ console.log("No action needed.");
+ return;
+ }
+
+ // Extracting command and parameters
+ const command = getActionFromComment(commentBody);
+
+ if (command === "label") {
+ const label = getArgFromComment(1);
+ // Add label
+ await octokit.rest.issues.addLabels({
+ owner,
+ repo,
+ issue_number,
+ labels: [label],
+ });
+ } else if (command === "unlabel") {
+ // Remove label
+ const label = getArgFromComment(1);
+ await octokit.rest.issues.removeLabel({
+ owner,
+ repo,
+ issue_number,
+ name: label,
+ }).catch(error => {
+ // Handle the case where the label does not exist to avoid failing the action
+ if (error.status !== 404) {
+ throw error;
+ }
+ });
+ }
+ } catch (error) {
+ core.setFailed(error.message);
+ }
+}
+
+run();
diff --git a/.github/workflows/supersetbot.yml b/.github/workflows/supersetbot.yml
new file mode 100644
index 0000000000..6e044b51bf
--- /dev/null
+++ b/.github/workflows/supersetbot.yml
@@ -0,0 +1,17 @@
+- name: supersetbot
+ id: supersetbot
+ run: node .github/workflows/supersetbot.js
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ COMMENT_BODY: ${{ github.event.comment.body }}
+
+ jobs:
+ supersetbot:
+ runs-on: ubuntu-latest
+ if: "contains(github.event.comment.body, '@supersetbot')"
+ steps:
+ - name: Process supersetbot Command
+ run: node .github/scripts/process_command.js
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ COMMENT_BODY: ${{ github.event.comment.body }}