Skip to content

Commit 5106e93

Browse files
authored
fix: auto assign is not working correctly (#220)
* fix: auto assign is not working correctly * wip
1 parent da839b4 commit 5106e93

File tree

2 files changed

+68
-50
lines changed

2 files changed

+68
-50
lines changed

src/plugins/auto-assign/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function isWillingToSubmitPR(body) {
2525
return body
2626
.toLowerCase()
2727
.includes(
28-
"- [x] i am willing to submit a pull request to implement this change."
28+
"- [x] i am willing to submit a pull request"
2929
);
3030
}
3131

tests/plugins/auto-assign/index.js

Lines changed: 67 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ const autoAssign = require("../../../src/plugins/auto-assign");
1616
// Helpers
1717
//-----------------------------------------------------------------------------
1818

19-
const API_ROOT = "https://api.github.com";
19+
const API_URL = "https://api.github.com/repos/test/repo-test/issues/1/assignees";
20+
21+
/**
22+
* Returns an array of strings representing the issue body.
23+
* @param {'x' | ''} checkMark Check mark to use in the issue body.
24+
* @returns {string[]} Array of strings representing the issue body.
25+
*/
26+
function issueBodies(checkMark) {
27+
return [
28+
`- [${checkMark}] I am willing to submit a pull request for this issue.`,
29+
`- [${checkMark}] I am willing to submit a pull request for this change.`,
30+
`- [${checkMark}] I am willing to submit a pull request to implement this rule.`,
31+
`- [${checkMark}] I am willing to submit a pull request to implement this change.`
32+
]
33+
}
2034

2135
//-----------------------------------------------------------------------------
2236
// Tests
@@ -37,6 +51,11 @@ describe("auto-assign", () => {
3751
});
3852

3953
autoAssign(bot);
54+
55+
fetchMock.mockGlobal().post(
56+
API_URL,
57+
{ status: 200 }
58+
);
4059
});
4160

4261
afterEach(() => {
@@ -47,62 +66,61 @@ describe("auto-assign", () => {
4766

4867
describe("issue opened", () => {
4968
test("assigns issue to author when they indicate willingness to submit PR", async () => {
50-
fetchMock.mockGlobal().post(
51-
`${API_ROOT}/repos/test/repo-test/issues/1/assignees`,
52-
{ status: 200 }
53-
);
54-
55-
await bot.receive({
56-
name: "issues",
57-
payload: {
58-
action: "opened",
59-
installation: {
60-
id: 1
61-
},
62-
issue: {
63-
number: 1,
64-
body: "- [x] I am willing to submit a pull request to implement this change.",
65-
user: {
66-
login: "user-a"
67-
}
68-
},
69-
repository: {
70-
name: "repo-test",
71-
owner: {
72-
login: "test"
69+
for (const body of issueBodies("x")) {
70+
await bot.receive({
71+
name: "issues",
72+
payload: {
73+
action: "opened",
74+
installation: {
75+
id: 1
76+
},
77+
issue: {
78+
number: 1,
79+
body,
80+
user: {
81+
login: "user-a"
82+
}
83+
},
84+
repository: {
85+
name: "repo-test",
86+
owner: {
87+
login: "test"
88+
}
7389
}
7490
}
75-
}
76-
});
91+
});
7792

78-
expect(fetchMock.callHistory.called(`${API_ROOT}/repos/test/repo-test/issues/1/assignees`)).toBeTruthy();
93+
expect(fetchMock.callHistory.called(API_URL)).toBeTruthy();
94+
}
7995
});
8096

8197
test("does not assign issue when author does not indicate willingness to submit PR", async () => {
82-
await bot.receive({
83-
name: "issues",
84-
payload: {
85-
action: "opened",
86-
installation: {
87-
id: 1
88-
},
89-
issue: {
90-
number: 1,
91-
body: "- [] I am willing to submit a pull request to implement this change.",
92-
user: {
93-
login: "user-a"
94-
}
95-
},
96-
repository: {
97-
name: "repo-test",
98-
owner: {
99-
login: "test"
98+
for (const body of issueBodies("")) {
99+
await bot.receive({
100+
name: "issues",
101+
payload: {
102+
action: "opened",
103+
installation: {
104+
id: 1
105+
},
106+
issue: {
107+
number: 1,
108+
body,
109+
user: {
110+
login: "user-a"
111+
}
112+
},
113+
repository: {
114+
name: "repo-test",
115+
owner: {
116+
login: "test"
117+
}
100118
}
101119
}
102-
}
103-
});
120+
});
104121

105-
expect(fetchMock.callHistory.called()).toBe(false);
122+
expect(fetchMock.callHistory.called(API_URL)).toBe(false);
123+
}
106124
});
107125
});
108-
});
126+
});

0 commit comments

Comments
 (0)