Skip to content

Commit 5bfa2df

Browse files
committed
fix: get the correct installation specific octokit instance to remove label
1 parent 3b54df3 commit 5bfa2df

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ http
151151
routes.cla(req, res);
152152
break;
153153
case "POST /cla":
154-
routes.submitCla(req, res, app.octokit);
154+
routes.submitCla(req, res, app);
155155
break;
156156
case "POST /api/webhook":
157157
middleware(req, res);

src/helpers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,20 @@ export async function isOrgMember(octokit, org, username) {
7070
}
7171
}
7272

73-
export async function afterCLA(octokit, claSignatureInfo) {
73+
export async function getOctokitForRepo(app, owner, repo) {
74+
for await (const { installation } of app.eachInstallation.iterator()) {
75+
for await (const { octokit, repository } of app.eachRepository.iterator({
76+
installationId: installation.id,
77+
})) {
78+
if (repository.owner.login === owner && repository.name === repo) {
79+
return octokit;
80+
}
81+
}
82+
}
83+
throw new Error(`Installation not found for repository ${owner}/${repo}`);
84+
}
85+
86+
export async function afterCLA(app, claSignatureInfo) {
7487
if (!claSignatureInfo || !claSignatureInfo.referrer) return;
7588
const { org, repo, prNumber } = parseUrlQueryParams(
7689
claSignatureInfo.referrer,
@@ -83,6 +96,7 @@ export async function afterCLA(octokit, claSignatureInfo) {
8396
return;
8497
}
8598
try {
99+
let octokit = await getOctokitForRepo(app, org, repo);
86100
await octokit.rest.issues.removeLabel({
87101
owner: org,
88102
repo: repo,

src/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const routes = {
3838
});
3939
},
4040

41-
submitCla(req, res, octokit) {
41+
submitCla(req, res, app) {
4242
let body = "";
4343
req.on("data", (chunk) => {
4444
body += chunk.toString(); // convert Buffer to string
@@ -54,7 +54,7 @@ export const routes = {
5454
const serverTimestamp = new Date().toISOString();
5555
bodyJson.serverTimestamp = serverTimestamp;
5656
storage.save(bodyJson);
57-
await afterCLA(octokit, bodyJson);
57+
await afterCLA(app, bodyJson);
5858
// Referrer has information about which PR this CLA flow started from
5959
const { org, repo, prNumber } = parseUrlQueryParams(bodyJson.referrer);
6060
if (org && repo && prNumber) {

0 commit comments

Comments
 (0)