diff --git a/README.md b/README.md index 518e53f..f3f8046 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,6 @@ Hello beautiful world! 🌎 1. Receive feedback from your teammates 1. Push updates 1. If `announcement-drafter` bot asks, make sure to authenticate so it can post as the author and not as itself -1. Approve the discussion to be created by reacting (not replying) with a 🚀 1. Merge the pull request 1. `announcement-drafter` will create the discussion 1. `announcement-drafter` will reply to the comment with a link to the newly created discussion diff --git a/web-app/src/eventHandlers/pullRequestEventHandler.ts b/web-app/src/eventHandlers/pullRequestEventHandler.ts index dd3676d..453ca2a 100644 --- a/web-app/src/eventHandlers/pullRequestEventHandler.ts +++ b/web-app/src/eventHandlers/pullRequestEventHandler.ts @@ -20,11 +20,6 @@ interface PullInfo { export class PullRequestEventHandler { private readonly errorIcon = "⛔️"; - private readonly approverPrefix = "To approve, @"; - private readonly approvalReaction = { - icon: "🚀", - label: "rocket", - }; private _tokenService: TokenService; private _configService: ConfigService; @@ -113,10 +108,7 @@ export class PullRequestEventHandler { throw new Error("Markdown is missing a repo or team to post the discussion to"); } - let commentBody = - `⚠️ ${appLinkMarkdown} will create a discussion using this file once this PR is merged ⚠️\n\n` + - "**IMPORTANT**:\n\n" + - `- ${this.approverPrefix}${authorLogin} must react (not reply) to this comment with a ${this.approvalReaction.icon}\n`; + let commentBody = `⚠️ ${appLinkMarkdown} will create a discussion using this file once this PR is merged ⚠️\n\n` + "**IMPORTANT**:\n\n"; const userRefreshToken = await this._tokenService.getRefreshToken({ userLogin: authorLogin, @@ -214,7 +206,7 @@ export class PullRequestEventHandler { return; } - // 1. (Shortcut) Look for comments made by the app and which files they were made on + // Get pull request comments const app = await appGitHubService.getAuthenticatedApp(); const appLogin = `${app.slug}[bot]`; const postFooter = `\n\n
This discussion was created using ${app.name}.\n`; @@ -223,7 +215,7 @@ export class PullRequestEventHandler { ...pullInfo, }); - // Our app will skip it if our comment has been edited (for security) + // Get comments made by the bot const botComments = pullRequestComments.filter( (comment) => comment.user.login === appLogin && !comment.in_reply_to_id && comment.path && !comment.body.includes(this.errorIcon) ); @@ -237,30 +229,22 @@ export class PullRequestEventHandler { const authorLogin = payload.pull_request.user.login; const authorToken = await this._tokenService.refreshUserToken(authorLogin); - // 2. Check for the approval reaction made by the author + // For each file to post for (const fileToPostComment of botComments) { - const reactions = await appGitHubService.getPullRequestCommentReaction({ - ...pullInfo, - comment_id: fileToPostComment.id, - }); - const authorApprovalReaction = reactions.find((reaction) => reaction.content === this.approvalReaction.label && reaction.user?.login === authorLogin); - if (authorApprovalReaction) { - logger.info("Found an approval!"); - // 3. Create the discussions based off of the file - const filepath = fileToPostComment.path; - try { - await this.createDiscussion(appGitHubService, logger, appConfig, { - filepath: filepath, - pullInfo: pullInfo, - userToken: authorToken, - dryRun: false, - pullRequestCommentId: fileToPostComment.id, - postFooter: postFooter, - }); - } catch (err) { - const errorMessage = HelperService.getErrorMessage(err); - logger.error(errorMessage); - } + // Create the discussion! + const filepath = fileToPostComment.path; + try { + await this.createDiscussion(appGitHubService, logger, appConfig, { + filepath: filepath, + pullInfo: pullInfo, + userToken: authorToken, + dryRun: false, + pullRequestCommentId: fileToPostComment.id, + postFooter: postFooter, + }); + } catch (err) { + const errorMessage = HelperService.getErrorMessage(err); + logger.error(errorMessage); } } // Delete the token to avoid conflicts with prod diff --git a/web-app/src/services/githubService.ts b/web-app/src/services/githubService.ts index ca06180..939f3aa 100644 --- a/web-app/src/services/githubService.ts +++ b/web-app/src/services/githubService.ts @@ -8,7 +8,7 @@ import { ProbotOctokit } from "probot"; import { DeprecatedLogger } from "probot/lib/types"; import { AppConfig } from "../models/appConfig"; import { Content } from "../models/fileContent"; -import { GitHubApp, PullRequestComment, PullRequestCommentReaction, TeamDiscussion } from "../models/githubModels"; +import { GitHubApp, PullRequestComment, TeamDiscussion } from "../models/githubModels"; export type OctokitPlus = Octokit & RestEndpointMethods & Api & PaginateInterface & API; @@ -196,17 +196,6 @@ export class GitHubService { return comments.data; } - public async getPullRequestCommentReaction(options: { owner: string; repo: string; comment_id: number }): Promise { - this._logger.info(`Getting pull request comment reactions...`); - this._logger.debug(`Options: ${JSON.stringify(options)}`); - const commentReactions = await this._octokit.reactions.listForPullRequestReviewComment({ - ...options, - per_page: 100, - }); - this._logger.info("Done."); - return commentReactions.data as PullRequestCommentReaction[]; - } - // https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions#creatediscussion public async createRepoDiscussion(options: { repoNodeId: string;