Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Fix the 'addComment' and 'addBadge' prebuild features in the Gitpod GitHub App #4043

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions components/server/ee/src/prebuilds/github-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class GithubApp extends Probot {
}

const newBody = body + `\n\n${button}\n\n`;
const updatePrPromise: Promise<void> = (ctx.github as any).pullRequests.update({ ...ctx.repo(), number: pr.number, body: newBody });
const updatePrPromise = ctx.octokit.pulls.update({ ...ctx.repo(), pull_number: pr.number, body: newBody });
updatePrPromise.catch(err => log.error(err, "Error while updating PR body", { contextURL }));
}

Expand All @@ -265,21 +265,21 @@ export class GithubApp extends Probot {

if (ctx.payload.action === 'synchronize') {
// someone just pushed a commit, remove the label
const delLabelPromise: Promise<void> = (ctx.github as any).issues.removeLabel({ ...ctx.repo(), number: pr.number, name: label });
const delLabelPromise = ctx.octokit.issues.removeLabel({ ...ctx.repo(), number: pr.number, name: label });
delLabelPromise.catch(err => log.error(err, "Error while removing label from PR"));
}

if (prebuildStartPromise) {
prebuildStartPromise.then(startWsResult => {
if (startWsResult.done) {
if (!!startWsResult.didFinish) {
const addLabelPromise: Promise<void> = (ctx.github as any).issues.addLabels({ ...ctx.repo(), number: pr.number, labels: [label] });
const addLabelPromise = ctx.octokit.issues.addLabels({ ...ctx.repo(), number: pr.number, labels: [label] });
addLabelPromise.catch(err => log.error(err, "Error while adding label to PR"));
}
} else {
new PrebuildListener(this.messageBus, startWsResult.wsid, evt => {
if (!HeadlessWorkspaceEventType.isRunning(evt) && HeadlessWorkspaceEventType.didFinish(evt)) {
const addLabelPromise: Promise<void> = (ctx.github as any).issues.addLabels({ ...ctx.repo(), number: pr.number, labels: [label] });
const addLabelPromise = ctx.octokit.issues.addLabels({ ...ctx.repo(), number: pr.number, labels: [label] });
addLabelPromise.catch(err => log.error(err, "Error while adding label to PR"));
}
});
Expand All @@ -297,14 +297,14 @@ export class GithubApp extends Probot {
const pr = ctx.payload.pull_request;
const contextURL = pr.html_url;
const button = `<a href="${this.env.hostUrl.withContext(contextURL)}"><img src="${this.getBadgeImageURL()}"/></a>`;
const comments = await ((ctx.github as any).issues.listComments(ctx.issue()) as Promise<any>);
const comments = await ctx.octokit.issues.listComments(ctx.issue());
const existingComment = comments.data.find((c: any) => c.body.indexOf(button) > -1);
if (existingComment) {
return;
}

const newComment = ctx.issue({ body: `\n\n${button}\n\n` });
const newCommentPromise: Promise<void> = (ctx.github as any).issues.createComment(newComment);
const newCommentPromise = ctx.octokit.issues.createComment(newComment);
newCommentPromise.catch(err => log.error(err, "Error while adding new PR comment", { contextURL }));
}

Expand Down