From c7cbbd0f2ded43e054a5b81d32a7b31c6d1306ca Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Sun, 18 Oct 2020 18:29:04 -0700 Subject: [PATCH] separate authors and commenters into individual parameters and update search date method (#8) --- README.md | 17 ++++++++++------- action.yml | 18 ++++++++++++------ dist/index.js | 40 +++++++++++++++++++++++++++------------- index.js | 38 ++++++++++++++++++++++++++------------ 4 files changed, 75 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 16c238b..4dc9477 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,15 @@ This action searches for team pings in issues and pull requests in an organizati # Input parameters - `token`: **Required:** An access token. -- `team`: **Required:** Name of the team whose @mentions you wannt to search for. Use the team name without the organization. For example: `docs-content-ecosystem`. -- `org`: **Required:** The organization to search for issues. -- `since`: The start date to search for team pings. Form: {4 digit year}-{month}-{day}. For example: '2020-5-20'. Default: '2020-1-1' +- `team`: **Required:** The team ping to search for that is part of the `org` specified below. Do not include the org name (for example, use `docs-content-ecosystem`). Issues and pull requests authored or commented on by members of `team` are ignored unless you specify an alternate `ignore-team` parameter. +- `org`: **Required:** The organization where the action should search for issues and pull requests. +- `since`: The start date to search for team pings. The action searches for activity that has occurred in an issue or pull request since the date specified. Form: {4 digit year}-{month}-{day}. For example: '2020-5-20' - `project-board`: 'The URL of the project board to place issues and pull requests. Must be an org project board. - `project-column`: The id of the column to add issues and pull requests.' -- `ignore-team`: Team whose members should respond to the `team` mentions. Issues and pull requests authored or commented on by members of this team are ignored. If you don't provide an `ignore-team`, the issues authored or commented on by members of `team` will be ignored. For example, you can use `ignore-team` to specify a team with more members than `team` or a team that includes only reviewers. +- `ignore-team`: Ignores issues and pull requests authored or commented on by members of this team. Issues and pull requests authored or commented on by members of `team` are ignored unless you specify an alternate `ignore-team` parameter. You can use `ignore-team` to specify a larger team or a team that does not match the team ping being searched. The value you specify for `ignore-team` overrides the `team` value. - `ignore-repos`: Repositories to ignore when searching issues and pull requests. You can add more than one repository by using a comma-separated list. Format: {owner}/{repo}. For example: octocat/hello-world -- `ignore-bot`: Ignores issues and pull requests authored or commented on by this bot account. +- `ignore-authors`: Ignores issues and pull requests authored by these accounts. You can add more than one repository by using a comma-separated list (for example, 'actions-bot, hubot') +- `ignore-commenters`: Ignores issues and pull requests commented by thee accounts. You can add more than one repository by using a comma-separated list (for example, 'actions-bot, hubot') - `comment-body`: A comment added to the issue or pull request. ## `token` @@ -50,7 +51,8 @@ jobs: project-board: 'https://github.com/orgs/spacelysprocketsinc/projects/1' project-column: 9 ignore-repos: 'spacelysprocketsinc/product-spacely, spacelysprocketsinc/product-spacely-sprockets' - ignore-bot: sprocketbot + ignore-authors: 'sprocketbot, github-actions' + ignore-commenters: 'sprocketbot' comment-body: ':rocket: Thanks for the ping! :bellhop_bell: This issue was added to our first-responder project board. A team member will be along shortly to review this issue.' first-responder-product-subteam: @@ -68,7 +70,8 @@ jobs: project-board: 'https://github.com/orgs/spacelysprocketsinc/projects/1' project-column: 10 ignore-repos: 'spacelysprocketsinc/product-spacely, spacelysprocketsinc/product-spacely-sprockets' - ignore-bot: sprocketbot + ignore-authors: 'sprocketbot, github-actions' + ignore-commenters: 'sprocketbot' comment-body: ':robot: Thanks for the ping to team sprockets! :bellhop_bell: This issue was added to our first-responder project board. A team member will be along shortly to review this issue.' ``` diff --git a/action.yml b/action.yml index ee13be9..5144001 100644 --- a/action.yml +++ b/action.yml @@ -5,13 +5,13 @@ inputs: description: 'An access token.' required: true team: # id of input - description: 'Team name without the organization. For example: `docs-content-ecosystem`' + description: 'The team ping to search for that is part of the `org` specified below. Do not include the org name (for example, use `docs-content-ecosystem`). Issues and pull requests authored or commented on by members of `team` are ignored unless you specify an alternate `ignore-team` parameter.' required: true org: - description: 'The organization to search for issues.' + description: 'The organization where the action should search for issues and pull requests.' required: true since: - description: 'The start date to search for team pings. Form: {4 digit year}-{month}-{day}. For example: 2020-5-20' + description: 'The start date to search for team pings. The action searches for activity that has occurred in an issue or pull request since the date specified. Form: {4 digit year}-{month}-{day}. For example: "2020-5-20"' required: false default: '2020-1-1' project-board: @@ -21,13 +21,19 @@ inputs: description: 'The id of the column to add issues and pull requests.' required: true ignore-team: - description: 'Ignores issues and pull requests authored or commented on by members of this team. By default `team` is used for this value. You can use `ignore-team` to specify a larger team or a team that does not match the team ping being searched.' + description: 'Ignores issues and pull requests authored or commented on by members of this team. Issues and pull requests authored or commented on by members of `team` are ignored unless you specify an alternate `ignore-team` parameter. You can use `ignore-team` to specify a larger team or a team that does not match the team ping being searched. The value you specify for `ignore-team` overrides the `team` value.' required: false ignore-repos: description: 'Repositories to ignore when searching issues and pull requests. You can add more than one repository by using a comma-separated list. Format: {owner}/{repo}. For example: octocat/hello-world' required: false - ignore-bot: - description: 'Ignores issues and pull requests authored or commented on by this bot account.' + ignore-authors: + description: 'Ignores issues and pull requests authored by these accounts. You can add more than one repository by using a comma-separated list (for example, "actions-bot, hubot")' + required: false + ignore-commenters: + description: 'Ignores issues and pull requests commented by thee accounts. You can add more than one repository by using a comma-separated list (for example, "actions-bot, hubot")' + required: false + ignore-labels: + description: 'Ignores issues and pull requests with specific labels. You can add more than one label by using a comma-separated list (for example, "space-2x, autogen")' required: false comment-body: description: 'A comment added to the issue or pull request.' diff --git a/dist/index.js b/dist/index.js index 9f1e7fe..b024a2e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -508,25 +508,31 @@ async function run () { const projectBoard = core.getInput('project-board') const columnId = parseInt(core.getInput('project-column'), 10) const ignoreTeam = core.getInput('ignore-team') - const ignoreBot = core.getInput('ignore-bot') const body = core.getInput('comment-body') const ignoreRepos = core.getInput('ignore-repos') !== '' ? core.getInput('ignore-repos').split(',').map(x => x.trim()) : [] + const ignoreLabels = core.getInput('ignore-labels') !== '' + ? core.getInput('ignore-labels').split(',').map(x => x.trim()) : [] + let ignoreAuthors = core.getInput('ignore-authors') !== '' + ? core.getInput('ignore-authors').split(',').map(x => x.trim()) : [] + let ignoreCommenters = core.getInput('ignore-commenters') !== '' + ? core.getInput('ignore-commenters').split(',').map(x => x.trim()) : [] const octokit = new GitHub(token) const projectInfo = await getProjectMetaData(projectBoard, org) // Create a list of users to ignore in the search query - let logins = '' + let teamMembers = [] if (ignoreTeam === '') { - logins = await getTeamLogins(octokit, org, team) + teamMembers = await getTeamLogins(octokit, org, team) } else { - logins = await getTeamLogins(octokit, org, ignoreTeam) + teamMembers = await getTeamLogins(octokit, org, ignoreTeam) } - if (ignoreBot !== '') logins.push(ignoreBot) + ignoreAuthors = ignoreAuthors.concat(teamMembers) + ignoreCommenters = ignoreCommenters.concat(teamMembers) // Assemble and run the issue/pull request search query - const issues = await getTeamPingIssues(octokit, org, fullTeamName, logins, since, projectInfo, ignoreRepos) + const issues = await getTeamPingIssues(octokit, org, fullTeamName, ignoreAuthors, ignoreCommenters, since, projectInfo, ignoreRepos, ignoreLabels) if (issues.data.incomplete_results === false) { console.log('🌵🌵🌵 All search results were found. 🌵🌵🌵') @@ -560,23 +566,31 @@ async function run () { return '🏁⛑' } -async function getTeamPingIssues (octokit, org, team, members, since = '2019-01-01', projectBoard, ignoreRepos) { +async function getTeamPingIssues (octokit, org, team, authors, commenters, since = '2019-01-01', projectBoard, ignoreRepos, ignoreLabels) { // Search for open issues in repositories owned by `org` // and includes a team mention to `team` - let query = `q=is%3Aopen+org%3A${org}+team%3A${team}` - for (const member of members) { - query = query.concat(`+-commenter%3A${member}+-author%3A${member}`) + let query = `per_page=100&q=is%3Aopen+org%3A${org}+team%3A${team}` + for (const author of authors) { + query = query.concat(`+-author%3A${author}`) + } + for (const commenter of commenters) { + query = query.concat(`+-commenter%3A${commenter}`) } - // Add the created since date query - query = query.concat(`+created%3A%3E${since}`) + // Add the updated since date query + query = query.concat(`+updated%3A%3E${since}`) // Add ignore repos query ignoreRepos.forEach(elem => { query = query.concat(`+-repo%3A${elem}`) }) - // Ignore issues alrady on the project board + // Add ignore labels query + ignoreLabels.forEach(elem => { + query = query.concat(`+-label%3A${elem}`) + }) + + // Ignore issues already on the project board const ref = projectBoard.repo !== undefined ? `${projectBoard.owner}%2F${projectBoard.repo}` : projectBoard.owner query = query.concat(`+-project%3A${ref}%2F${projectBoard.number}`) diff --git a/index.js b/index.js index 59c60b4..5f015e1 100755 --- a/index.js +++ b/index.js @@ -11,25 +11,31 @@ async function run () { const projectBoard = core.getInput('project-board') const columnId = parseInt(core.getInput('project-column'), 10) const ignoreTeam = core.getInput('ignore-team') - const ignoreBot = core.getInput('ignore-bot') const body = core.getInput('comment-body') const ignoreRepos = core.getInput('ignore-repos') !== '' ? core.getInput('ignore-repos').split(',').map(x => x.trim()) : [] + const ignoreLabels = core.getInput('ignore-labels') !== '' + ? core.getInput('ignore-labels').split(',').map(x => x.trim()) : [] + let ignoreAuthors = core.getInput('ignore-authors') !== '' + ? core.getInput('ignore-authors').split(',').map(x => x.trim()) : [] + let ignoreCommenters = core.getInput('ignore-commenters') !== '' + ? core.getInput('ignore-commenters').split(',').map(x => x.trim()) : [] const octokit = new GitHub(token) const projectInfo = await getProjectMetaData(projectBoard, org) // Create a list of users to ignore in the search query - let logins = '' + let teamMembers = [] if (ignoreTeam === '') { - logins = await getTeamLogins(octokit, org, team) + teamMembers = await getTeamLogins(octokit, org, team) } else { - logins = await getTeamLogins(octokit, org, ignoreTeam) + teamMembers = await getTeamLogins(octokit, org, ignoreTeam) } - if (ignoreBot !== '') logins.push(ignoreBot) + ignoreAuthors = ignoreAuthors.concat(teamMembers) + ignoreCommenters = ignoreCommenters.concat(teamMembers) // Assemble and run the issue/pull request search query - const issues = await getTeamPingIssues(octokit, org, fullTeamName, logins, since, projectInfo, ignoreRepos) + const issues = await getTeamPingIssues(octokit, org, fullTeamName, ignoreAuthors, ignoreCommenters, since, projectInfo, ignoreRepos, ignoreLabels) if (issues.data.incomplete_results === false) { console.log('🌵🌵🌵 All search results were found. 🌵🌵🌵') @@ -63,23 +69,31 @@ async function run () { return '🏁⛑' } -async function getTeamPingIssues (octokit, org, team, members, since = '2019-01-01', projectBoard, ignoreRepos) { +async function getTeamPingIssues (octokit, org, team, authors, commenters, since = '2019-01-01', projectBoard, ignoreRepos, ignoreLabels) { // Search for open issues in repositories owned by `org` // and includes a team mention to `team` let query = `per_page=100&q=is%3Aopen+org%3A${org}+team%3A${team}` - for (const member of members) { - query = query.concat(`+-commenter%3A${member}+-author%3A${member}`) + for (const author of authors) { + query = query.concat(`+-author%3A${author}`) + } + for (const commenter of commenters) { + query = query.concat(`+-commenter%3A${commenter}`) } - // Add the created since date query - query = query.concat(`+created%3A%3E${since}`) + // Add the updated since date query + query = query.concat(`+updated%3A%3E${since}`) // Add ignore repos query ignoreRepos.forEach(elem => { query = query.concat(`+-repo%3A${elem}`) }) - // Ignore issues alrady on the project board + // Add ignore labels query + ignoreLabels.forEach(elem => { + query = query.concat(`+-label%3A${elem}`) + }) + + // Ignore issues already on the project board const ref = projectBoard.repo !== undefined ? `${projectBoard.owner}%2F${projectBoard.repo}` : projectBoard.owner query = query.concat(`+-project%3A${ref}%2F${projectBoard.number}`)