Skip to content

Commit 7dc7e37

Browse files
Varun-Kolanutimabbott
authored andcommitted
claim: Update logic to check whether a commenter is a contributor.
Fixes #230.
1 parent 3655e1f commit 7dc7e37

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/commands/claim.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@ export const run = async function (payload, commenter, args) {
103103
return invite.call(this, payload, commenter);
104104
}
105105

106-
const contributors = await this.util.getAllPages("repos.listContributors", {
106+
// A commenter is considered a contributor if they have at least one commit
107+
// in the repository. So, fetching just one commit by the author is sufficient
108+
// to determine whether they are a contributor or not.
109+
const commenterCommitsResponse = await this.repos.listCommits({
107110
owner: repoOwner,
108111
repo: repoName,
112+
author: commenter,
113+
per_page: 1,
109114
});
110115

111-
if (contributors.some((c) => c.login === commenter)) {
116+
if (commenterCommitsResponse.data.length > 0) {
117+
// commenter is a contributor
112118
return claim.call(this, commenter, number, repoOwner, repoName);
113119
}
114120

test/unit/commands/claim.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,16 @@ test("Throw error if permission is not specified", async () => {
206206
scope.done();
207207
});
208208

209-
test("Always assign if commenter is contributor", async () => {
209+
test("Always assign if commenter has at least one commit", async () => {
210210
const commenter = "octocat";
211211
client.cfg.issues.commands.assign.warn.presence = false;
212212

213213
const scope = nock("https://api.github.com")
214214
.get(`/repos/zulip/zulipbot/collaborators/${commenter}`)
215215
.reply(204)
216-
.get("/repos/zulip/zulipbot/contributors")
217-
.reply(200, [{ login: "octocat" }])
216+
.get(`/repos/zulip/zulipbot/commits`)
217+
.query({ author: commenter, per_page: 1 })
218+
.reply(200, [{ sha: "dummysha123" }])
218219
.post("/repos/zulip/zulipbot/issues/69/assignees", {
219220
assignees: ["octocat"],
220221
})
@@ -232,8 +233,9 @@ test("Error if no assignees were added", async () => {
232233
const scope = nock("https://api.github.com")
233234
.get(`/repos/zulip/zulipbot/collaborators/${commenter}`)
234235
.reply(204)
235-
.get("/repos/zulip/zulipbot/contributors")
236-
.reply(200, [{ login: "octocat" }])
236+
.get(`/repos/zulip/zulipbot/commits`)
237+
.query({ author: commenter, per_page: 1 })
238+
.reply(200, [{ sha: "dummysha123" }])
237239
.post("/repos/zulip/zulipbot/issues/69/assignees", {
238240
assignees: ["octocat"],
239241
})
@@ -252,7 +254,8 @@ test("Assign if claim limit validation passed", async () => {
252254
const scope = nock("https://api.github.com")
253255
.get(`/repos/zulip/zulipbot/collaborators/${commenter}`)
254256
.reply(204)
255-
.get("/repos/zulip/zulipbot/contributors")
257+
.get(`/repos/zulip/zulipbot/commits`)
258+
.query({ author: commenter, per_page: 1 })
256259
.reply(200, [])
257260
.get("/issues?filter=all&labels=in%20progress")
258261
.reply(200, [])
@@ -276,7 +279,8 @@ test("Reject claim limit validation failed", async () => {
276279
const scope = nock("https://api.github.com")
277280
.get(`/repos/zulip/zulipbot/collaborators/${commenter}`)
278281
.reply(204)
279-
.get("/repos/zulip/zulipbot/contributors")
282+
.get(`/repos/zulip/zulipbot/commits`)
283+
.query({ author: commenter, per_page: 1 })
280284
.reply(200, [])
281285
.get("/issues?filter=all&labels=in%20progress")
282286
.reply(200, [{ assignees: [{ login: "octocat" }] }])
@@ -297,7 +301,8 @@ test("Reject claim limit validation failed (limit over 1)", async () => {
297301
const scope = nock("https://api.github.com")
298302
.get(`/repos/zulip/zulipbot/collaborators/${commenter}`)
299303
.reply(204)
300-
.get("/repos/zulip/zulipbot/contributors")
304+
.get(`/repos/zulip/zulipbot/commits`)
305+
.query({ author: commenter, per_page: 1 })
301306
.reply(200, [])
302307
.get("/issues?filter=all&labels=in%20progress")
303308
.reply(200, [

0 commit comments

Comments
 (0)