Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to ignore specified users & collaborators #5

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ With this GitHub workflow, you can automate tasks whenever an author creates mul
### Use cases

- The workflow can comment the issues that are already created by the author which are currently in the open state.
- You can also filter the issues that are assigned to you
- You can also filter the issues that are assigned to the author of the issue
- You can add your own comment message (even multiline) in the issue.
- You can add label or labels based on your preferences.
- Optionally, you can also close the issue (previous issues won't be affected), and only the current issue will be closed.
- You can ignore this workflow for specific users by using `ignoreUsers`
- You can directly pass `ignoreCollaborators`

---

Expand Down Expand Up @@ -53,6 +55,8 @@ Various inputs are defined to let you configure the action:
| `close` | This will close the issue if set to true | `'false'` |
| `issueNumber` | This will comment all the previous issues that are created by the author | `'true'` |
| `assign` | This will filter the issues that are assigned to the author (works only if `issueNumber` is `true`) | `'false'` |
| `ignoreUsers` | Specify usernames that should be ignored while running this workflow. Use commas to separate if there are multiple users. | `''` |
| `ignoreCollaborators` | This will ignore all the collaborators in the repository while running this workflow | `'false'` |

<br>

Expand Down Expand Up @@ -180,6 +184,50 @@ with:

</details>

<br>

<details>
<summary>To ignore specified users while running this workflow</summary>

<br>

- Suppose, we have to ignore this workflow for users with username: `Anmol-Baranwal`, `AnmolB2`.

```yml
uses: Anmol-Baranwal/handle-multiple-issues@v1
with:
issueNumber: true # default is true
ignoreUsers: 'Anmol-Baranwal, AnmolB2'

# Suppose Anmol-Baranwal created an issue. You will receive a log message during the workflow execution.
# Log Message
# User: Anmol-Baranwal is on the ignore list. Ignoring the workflow for this user.
```

</details>

<br>

<details>
<summary>To ignore collaborators of the repository while running this workflow</summary>

<br>

- Suppose, we have to ignore this workflow for users with username: `Anmol-Baranwal`, `AnmolB2`.

```yml
uses: Anmol-Baranwal/handle-multiple-issues@v1
with:
issueNumber: true # default is true
ignoreCollaborators: true

# Suppose Anmol-Baranwal created an issue and is a collaborator. You will receive a log message during the workflow execution.
# Log Message
# User: Anmol-Baranwal is a collaborator. Ignoring the issue for collaborators.
```

</details>

---

### 🤝 How to Contribute?
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ inputs:
description: 'To filter the issues that are assigned to the author'
default: 'false'
required: false
ignoreUsers:
description: 'Specify usernames that should be ignored while running this workflow'
default: ''
required: false
ignoreCollaborators:
description: 'Ignore all the collaborators in the repository while running this workflow'
default: 'false'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
40 changes: 32 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,50 @@ async function HandleMultipleIssues() {
const context = github.context;
core.notice("step 1.");
// Retrieve custom inputs
const labels = core.getInput("label").split(",").map(label => label.trim());
const labels = core
.getInput("label")
.split(",")
.map((label) => label.trim());
const assign = core.getInput("assign") === "true" || false;
const issueNumber = core.getInput("issueNumber") === "true";
const comment = core.getInput("comment");
const close = core.getInput("close") === "true" || false;
const ignoreUsers = core
.getInput("ignoreUsers")
.split(",")
.map((user) => user.trim());
const ignoreCollaboratorsInput = core.getInput("ignoreCollaborators") === "true" || false;
const checkComment = comment.trim() !== "";
// Check if the same author has open issues
const author = (_a = context.payload.issue) === null || _a === void 0 ? void 0 : _a.user.login;
if (ignoreUsers.includes(author)) {
core.notice(`User: ${author} is on the ignore list. Ignoring the workflow for this user.`);
return; // No need to continue.
}
const collaboratorUsernames = ignoreCollaboratorsInput
? (await octokit.rest.repos.listCollaborators({
owner: context.repo.owner,
repo: context.repo.repo
})).data.map((collaborator) => collaborator.login)
: [];
if (collaboratorUsernames.includes(author)) {
core.notice(`User ${author} is a collaborator. Ignoring the issue for collaborators.`);
return; // No need to continue.
}
core.notice("step 2.");
const { data: authorIssues } = await octokit.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
creator: author,
state: "open",
state: "open"
});
const filteredIssues = assign
? authorIssues.filter((issue) => issue.assignees.some((assignee) => assignee.login === author))
: authorIssues;
if (filteredIssues.length === 0) {
core.notice(`No existing ${assign === true ? "issues created by and assigned to" : "open issues for"} this author.`);
core.notice(`No existing ${assign === true
? "issues created by and assigned to"
: "open issues for"} this author.`);
return; // No need to continue.
}
core.notice("step 3.");
Expand All @@ -86,7 +110,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
labels: [lbl],
labels: [lbl]
});
}
}
Expand All @@ -96,7 +120,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
labels: [labels],
labels: [labels]
});
}
core.notice("Labels added to issue #" + issueNumberToLabel);
Expand All @@ -119,7 +143,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
body: commentText,
body: commentText
});
core.notice("Comment added to issue #" + issueNumberToLabel);
}
Expand All @@ -129,7 +153,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
body: comment,
body: comment
});
core.notice("Comment added to issue #" + issueNumberToLabel);
}
Expand All @@ -139,7 +163,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
state: "closed",
state: "closed"
});
core.notice("Issue #" + issueNumberToLabel + " closed");
}
Expand Down
Loading
Loading