Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import * as octokit from '@octokit/rest';
import similarity from 'string-similarity';
import { CreateIssueCommentParams, PullRequestUpdateParams, UpdateLabelParams } from './types';
import { CreateIssueCommentParams, PullRequestParams, PullRequestUpdateParams, UpdateLabelParams } from './types';
import { BOT_BRANCH_PATTERNS, DEFAULT_BRANCH_PATTERNS, MARKER_REGEX } from './constants';

export class GitHub {
Expand Down Expand Up @@ -68,6 +68,25 @@ export class GitHub {
}
};

/** Get the PR description. */
getPRDescription = async (pr: PullRequestParams): Promise<string | null> => {
try {
const { owner, repo, number } = pr;
const { data } = await this.client.pulls.get({
owner,
repo,
// eslint-disable-next-line @typescript-eslint/naming-convention
pull_number: number,
});
return data.body;
} catch (error) {
console.error(error);
// eslint-disable-next-line i18n-text/no-en
core.setFailed((error as Error)?.message ?? 'Failed to fetch latest PR description');
throw error;
}
};

/** Get a comment based on story title and PR title similarity. */
getPRTitleComment = (storyTitle: string, prTitle: string): string => {
const matchRange: number = similarity.compareTwoStrings(storyTitle, prTitle);
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ async function run(): Promise<void> {
base: { ref: baseBranch },
head: { ref: headBranch },
number: prNumber = 0,
body: prBody = '',
additions = 0,
title = '',
} = pullRequest as PullRequestParams;
Expand Down Expand Up @@ -149,6 +148,11 @@ async function run(): Promise<void> {

await gh.addLabels({ ...commonPayload, labels });

const pr = pullRequest as PullRequestParams;
pr.owner = owner;
pr.repo = repo;
const prBody = await gh.getPRDescription(pr);

if (GitHub.shouldUpdatePRDescription(prBody)) {
console.log('Updating PR description…', prBody);

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PullRequestUpdateParams extends UpdateParams {
body?: string;
}

export interface PullRequestParams {
export interface PullRequestParams extends UpdateParams {
number: number;
// eslint-disable-next-line @typescript-eslint/naming-convention
html_url?: string;
Expand Down