From 87cdcf34a59b905111af3539a73ac6a6728f07d2 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Sat, 10 Feb 2024 18:20:04 -0800 Subject: [PATCH] require --- .github/workflows/supersetbot.yml | 4 +-- .github/workflows/supersetbot/src/commands.js | 35 ++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/.github/workflows/supersetbot.yml b/.github/workflows/supersetbot.yml index 78da702a2233e..5cda96594b123 100644 --- a/.github/workflows/supersetbot.yml +++ b/.github/workflows/supersetbot.yml @@ -32,8 +32,8 @@ jobs: const cmd = context.eventName === 'workflow_dispatch' ? context.payload.inputs.comment_body : context.payload.comment.body; - - const modulePath = '.github/workflows/supersetbot/src/index.js'; + const githubWorkspace = process.env.GITHUB_WORKSPACE; + const modulePath = `${githubWorkspace}/.github/workflows/supersetbot/src/index.js`; const { runCliCommand } = await import(modulePath); runCliCommand(cmd); })(); diff --git a/.github/workflows/supersetbot/src/commands.js b/.github/workflows/supersetbot/src/commands.js index 7039b1fd08425..a605f00256192 100644 --- a/.github/workflows/supersetbot/src/commands.js +++ b/.github/workflows/supersetbot/src/commands.js @@ -1,3 +1,4 @@ +import { ORG_LIST } from './metadata.js'; /* eslint-disable no-shadow */ export function commandWrapper(commandFunc, context, verbose = false) { @@ -48,30 +49,24 @@ export function unlabel(repo, issueNumber, label, github) { }); } -export async function assignOrgLabel(issueNumber, github) { +export async function assignOrgLabel(repo, issueNumber, github) { - const username = issue.user.login; + const issue = await github.rest.issues.get({ + ...unPackRepo(repo), + issue_number: issueNumber, + }); + + const username = issue.data.user.login; const orgs = await github.orgs.listForUser({ username }); const orgNames = orgs.data.map(v => v.login); // get list of matching github orgs - let matchingOrgs = orgNames.filter(org => conf.ORG_WHITELIST.includes(org)); - // append user-based orgs from list - if (conf.USER_ORG_XREF[username]) { - matchingOrgs.push(conf.USER_ORG_XREF[username]); + let matchingOrgs = orgNames.filter(org => ORG_LIST.includes(org)); + if (matchingOrgs.length) { + return github.rest.issues.addLabels({ + ...unPackRepo(repo), + issue_number: issueNumber, + labels: [matchingOrgs], + }); } - // look up org groups, add 'em in! - const orgGroups = []; - matchingOrgs.forEach(org => { - if (conf.ORG_GROUPS[org]) { - orgGroups.push(conf.ORG_GROUPS[org]); - } - }); - matchingOrgs.concat(orgGroups); - // dedupe, just in case - matchingOrgs = new Set(matchingOrgs); - matchingOrgs.forEach(org => { - return github.issues.addLabels( - context.issue({ issue_number: issue.number, labels: [org] })); - }); }