|
1 | 1 | import * as core from '@actions/core' |
2 | 2 | import * as github from '@actions/github' |
3 | 3 | import type { IssueCommentEvent, IssuesEvent } from '@octokit/webhooks-types' |
| 4 | +import { dedent } from 'ts-dedent' |
4 | 5 | import { AllowedIssueAction, Common } from './enums.js' |
5 | 6 | import * as issues from './github/issues.js' |
6 | 7 | import * as repos from './github/repos.js' |
@@ -166,6 +167,26 @@ export async function addUser( |
166 | 167 | email: payload.comment.body.split(' ')[1].split(',')[1] |
167 | 168 | } |
168 | 169 |
|
| 170 | + // Check if the user is already in the team and the repository already exists. |
| 171 | + if ( |
| 172 | + (await repos.exists(request, user)) && |
| 173 | + (await teams.getMembers(request)) |
| 174 | + .map((user) => user.handle) |
| 175 | + .includes(user.handle) |
| 176 | + ) { |
| 177 | + // Add a comment that the user is already added. |
| 178 | + const token: string = core.getInput('github_token', { required: true }) |
| 179 | + const octokit = github.getOctokit(token) |
| 180 | + |
| 181 | + // Add the error comment to the request issue. |
| 182 | + await octokit.rest.issues.createComment({ |
| 183 | + issue_number: (payload as IssueCommentEvent).issue.number, |
| 184 | + owner: Common.OWNER, |
| 185 | + repo: Common.ISSUEOPS_REPO, |
| 186 | + body: dedent`User \`${user.handle}\` is already added!` |
| 187 | + }) |
| 188 | + } |
| 189 | + |
169 | 190 | const team = await teams.get(request) |
170 | 191 |
|
171 | 192 | // Add the user to the team. |
|
0 commit comments