Skip to content

Commit 07297dc

Browse files
committed
maint : updating readme.md for the added changes
1 parent 0a4e636 commit 07297dc

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

__tests__/github.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ describe('With a new github client', () => {
161161
})
162162

163163
test('hasLabel returns true if the label already exists on the issue or pr', () => {
164-
const result = client.hasLabel('community')
165-
expect(result).toBe(true)
164+
const result = client.getLabels()
165+
expect(result).toEqual(['community'])
166166
})
167167

168168
test('hasLabel returns false if the label does not exist on the issue or pr', () => {
169-
const result = client.hasLabel('test')
170-
expect(result).toBe(false)
169+
const result = client.getLabels()
170+
expect(result).toEqual(['community'])
171171
})
172172
})
173173

src/github.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ export class GitHubClient {
8888
}
8989

9090
// Checks if the issue already has the label
91-
hasLabel(name: string): boolean {
91+
getLabels(): string[] | false {
9292
let labels!: Label[]
9393

9494
if (github.context.eventName === 'issues') {
95-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9695
labels = (this.payload as IssuesEvent).issue.labels!
9796
} else if (
9897
github.context.eventName === 'pull_request' ||
@@ -103,7 +102,11 @@ export class GitHubClient {
103102
return false
104103
}
105104

106-
return labels.some((l) => l.name === name)
105+
if (labels.length > 0) {
106+
return labels.map((label) => label.name)
107+
}
108+
109+
return false
107110
}
108111

109112
/* Adds the label to the issue/pull request. It will attempt to create the label

src/main.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export async function run(): Promise<void> {
1414
const failIfMember = core.getInput('fail_if_member', {required: false})
1515
const orgs = getOrgMembershipList()
1616
const token = core.getInput('token', {required: true})
17-
1817
const client = new GitHubClient(token)
18+
const labels = client.getLabels()
1919

20-
if (client.hasLabel(labelName)) {
20+
if (labels && labels.includes(labelName)) {
21+
// "community" label exists
2122
core.info(`The '${labelName}' label is already present on this issue! 🙌`)
2223
return
2324
}
@@ -26,10 +27,8 @@ export async function run(): Promise<void> {
2627
(await client.checkOrgMembership(orgs)) ||
2728
client.isExcludedLogin(loginsToIgnore)
2829
) {
29-
if (failIfMember && !client.hasLabel(labelName)) {
30-
core.setFailed(
31-
'The PR does not have any labels, please add the labels!'
32-
)
30+
if (failIfMember && !labels) {
31+
core.setFailed('The PR does not have a label, please add one!')
3332
} else {
3433
core.info("Looks like this issue doesn't need labeling! 👍")
3534
}

0 commit comments

Comments
 (0)