Skip to content

Commit

Permalink
Merge pull request #5 from btwrk/feature/null-pr-body
Browse files Browse the repository at this point in the history
Pass body to pr update
  • Loading branch information
asbjornu authored Jul 29, 2022
2 parents 6ae34de + 633eff0 commit bd5a5cb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ some actual content'
});

it('should return true when the hidden marker is NOT present', () => {
expect(GitHub.shouldUpdatePRDescription(null)).toBeTruthy();
expect(GitHub.shouldUpdatePRDescription('')).toBeTruthy();
expect(GitHub.shouldUpdatePRDescription('added_by')).toBeTruthy();
expect(GitHub.shouldUpdatePRDescription('added_by_something_else')).toBeTruthy();
Expand Down
30 changes: 20 additions & 10 deletions __tests__/jira.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@ describe('getJIRAIssueKeys()', () => {
});

describe('getPRDescription()', () => {
const issue: JIRADetails = {
key: 'ABC-123',
url: 'url',
type: { name: 'feature', icon: 'feature-icon-url' },
estimate: 1,
labels: [{ name: 'frontend', url: 'frontend-url' }],
summary: 'Story title or summary',
project: { name: 'project', url: 'project-url', key: 'abc' },
status: 'In Progress',
};

it('should include the hidden marker when getting PR description', () => {
const issue: JIRADetails = {
key: 'ABC-123',
url: 'url',
type: { name: 'feature', icon: 'feature-icon-url' },
estimate: 1,
labels: [{ name: 'frontend', url: 'frontend-url' }],
summary: 'Story title or summary',
project: { name: 'project', url: 'project-url', key: 'abc' },
status: 'In Progress',
};
const description = Jira.getPRDescription('some_body', issue);

expect(GitHub.shouldUpdatePRDescription(description)).toBeFalsy();
Expand All @@ -71,6 +72,15 @@ describe('getPRDescription()', () => {
expect(description).toContain(issue.status);
expect(description).toContain(issue.labels[0].name);
});

it('should work with null description', () => {
const description = Jira.getPRDescription(null, issue);

expect(description).toContain(issue.key);
expect(description).toContain(issue.estimate.toString());
expect(description).toContain(issue.status);
expect(description).toContain(issue.labels[0].name);
});
});

describe('getNoIdComment()', () => {
Expand Down
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.

7 changes: 3 additions & 4 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ export class GitHub {
/** Update a PR details. */
updatePrDetails = async (prData: PullRequestUpdateParams): Promise<void> => {
try {
const { owner, repo, pullRequestNumber, body } = prData;
// eslint-disable-next-line @typescript-eslint/naming-convention
const { owner, repo, pullRequestNumber: pull_number } = prData;
// eslint-disable-next-line @typescript-eslint/naming-convention
await this.client.pulls.update({ owner, repo, pull_number });
await this.client.pulls.update({ owner, repo, pull_number: pullRequestNumber, body });
} catch (error) {
console.error(error);
// eslint-disable-next-line i18n-text/no-en
Expand Down Expand Up @@ -166,7 +165,7 @@ export class GitHub {
*/
static shouldUpdatePRDescription = (
/** The PR description/body as a string. */
body?: string
body: string | null
): boolean => {
if (typeof body === 'string' && body != null && body !== undefined) {
// Check if the body contains the hidden marker and return false
Expand Down
2 changes: 1 addition & 1 deletion src/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Jira {
};

/** Get PR description with story/issue details. */
static getPRDescription = (body: string, details: JIRADetails): string => {
static getPRDescription = (body: string | null, details: JIRADetails): string => {
const displayKey = details.key.toUpperCase();

let description = `
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ async function run(): Promise<void> {
if (GitHub.shouldUpdatePRDescription(prBody)) {
console.log('Updating PR description…', prBody);

const body: string = Jira.getPRDescription(prBody, details);
const description: string = Jira.getPRDescription(prBody, details);

const prData: PullRequestUpdateParams = {
owner,
repo,
pullRequestNumber: prNumber,
body,
body: description,
};
await gh.updatePrDetails(prData);

Expand Down

0 comments on commit bd5a5cb

Please sign in to comment.