Skip to content

Commit 2004344

Browse files
committed
Add check for duplicate adds
1 parent ffc10b8 commit 2004344

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gh-github-intermediate-issueops",
33
"description": "GitHub Intermediate Offering: IssueOps Automation",
4-
"version": "2.0.5",
4+
"version": "2.0.6",
55
"author": "Nick Alteen <[email protected]>",
66
"private": true,
77
"type": "module",

src/actions.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
33
import type { IssueCommentEvent, IssuesEvent } from '@octokit/webhooks-types'
4+
import { dedent } from 'ts-dedent'
45
import { AllowedIssueAction, Common } from './enums.js'
56
import * as issues from './github/issues.js'
67
import * as repos from './github/repos.js'
@@ -166,6 +167,26 @@ export async function addUser(
166167
email: payload.comment.body.split(' ')[1].split(',')[1]
167168
}
168169

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+
169190
const team = await teams.get(request)
170191

171192
// Add the user to the team.

0 commit comments

Comments
 (0)