From b08f0f88617f1e267d87ce127216d2f2962f238f Mon Sep 17 00:00:00 2001 From: Simon Davis Date: Tue, 7 Mar 2023 12:44:01 -0800 Subject: [PATCH] handle breaking changes in actions/github and filter out members with no results, source org/repo from env --- .gitignore | 2 +- action.yml | 3 --- src/index.js | 17 +++++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 508e6a9..c9ec842 100644 --- a/.gitignore +++ b/.gitignore @@ -113,5 +113,5 @@ dist # End of https://www.toptal.com/developers/gitignore/api/node -SECRETS.txt +secrets.data node_modules diff --git a/action.yml b/action.yml index ace312c..7a82c89 100644 --- a/action.yml +++ b/action.yml @@ -4,9 +4,6 @@ inputs: github_token: description: 'A valid github token for the organization' required: true - org: - description: 'The organization to use.' - required: true team_slug: description: The team slug whose members you want to information for. required: true diff --git a/src/index.js b/src/index.js index 6126115..f31af70 100644 --- a/src/index.js +++ b/src/index.js @@ -4,29 +4,30 @@ const axios = require("axios"); async function main() { const githubToken = core.getInput("github_token"); - const org = core.getInput("org"); - const repo = core.getInput("repo"); const teamSlug = core.getInput("team_slug"); const slackToken = core.getInput("slack_token"); const slackChannel = core.getInput("slack_channel"); + const [org, repo] = process.env.GITHUB_REPOSITORY.split('/'); + const octokit = github.getOctokit(githubToken); let membersResponse = []; try { - membersResponse = await octokit.teams.listMembersInOrg({ + membersResponse = await octokit.rest.teams.listMembersInOrg({ org, team_slug: teamSlug, }); } catch (error) { core.setFailed(`Getting members for '${org}' failed with error ${error}`); + throw error; } core.info(`Found ${membersResponse.data.length} AWS team members.`); const searchQueries = membersResponse.data.map(async (member) => { - const response = await octokit.search.issuesAndPullRequests({ - q: `is:pr is:open author:${member.login} draft:false repo:${org}/${repo}`, + const response = await octokit.rest.search.issuesAndPullRequests({ + q: `is:pr is:open author:${member.login} draft:false org:${org} repo: ${repo}`, }); return { @@ -42,6 +43,8 @@ async function main() { core.setFailed(`Getting search results failed with error ${error}`); } + searchResults = searchResults.filter(member => member.count > 0); + searchResults.sort((a, b) => { const nameA = a.member.toUpperCase(); const nameB = b.member.toUpperCase(); @@ -55,12 +58,10 @@ async function main() { return 0; }); - core.setOutput("stats", JSON.stringify(searchResults)); - let memberLines = ""; searchResults.forEach((member) => { - memberLines += ` : ${member.count}\n`; + memberLines += `< https://github.com/search?q=repo:${org}/${repo}+author:${member.member}+is:pr+is:open+draft:false|${member.member}> : ${member.count}\n`; }); const postMessageBody = {