Skip to content

Commit

Permalink
handle breaking changes in actions/github and filter out members with…
Browse files Browse the repository at this point in the history
… no results, source org/repo from env
  • Loading branch information
breathingdust committed Mar 7, 2023
1 parent c3ee5a2 commit b08f0f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ dist
# End of https://www.toptal.com/developers/gitignore/api/node


SECRETS.txt
secrets.data
node_modules
3 changes: 0 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -55,12 +58,10 @@ async function main() {
return 0;
});

core.setOutput("stats", JSON.stringify(searchResults));

let memberLines = "";

searchResults.forEach((member) => {
memberLines += `<https://github.com/search?q=repo:${org}/${repo}+author:${member.member}+is:pr+is:open+draft:false|${member.member}> : ${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 = {
Expand Down

0 comments on commit b08f0f8

Please sign in to comment.