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

debug recent body #52

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ node_modules

.npm

coverage
coverage
bun.lockb
25 changes: 17 additions & 8 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ describe('getPRDescription()', () => {
const issueInfo = 'new info about jira task';
const description = getPRDescription(oldPRBody, issueInfo);

expect(description).toEqual(`${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
expect(description).toEqual(`${HIDDEN_MARKER_START}
${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBody}`);
${HIDDEN_MARKER_END}${oldPRBody}`);
});

it('should replace issue info', () => {
Expand All @@ -78,10 +77,20 @@ ${oldPRBody}`);

const description = getPRDescription(oldPRBody, issueInfo);

expect(description).toEqual(`${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
expect(description).toEqual(`${HIDDEN_MARKER_START}
${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBodyInformation}`);
${HIDDEN_MARKER_END}${oldPRBodyInformation}`);
});

it('should preserve identity', () => {
const oldPRBodyInformation = 'old PR description body';
const oldPRBody = `${HIDDEN_MARKER_START}Here is some old issue information${HIDDEN_MARKER_END}${oldPRBodyInformation}`;
const issueInfo = 'new info about jira task';

const description = getPRDescription(oldPRBody, issueInfo);
const identity = getPRDescription(description, issueInfo);

expect(description).toEqual(identity);
})
});
13,532 changes: 13,531 additions & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Add JIRA issue details to your GitHub pull request",
"main": "lib/index.js",
"scripts": {
"build": "engines-ok && ncc build src/main.ts -o lib -m",
"build": "engines-ok && ncc build src/main.ts -o lib",
"test": "jest",
"test:watch": "jest --watch",
"prettier": "prettier --write '**/*.ts'",
Expand Down
8 changes: 7 additions & 1 deletion src/github-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,17 @@ export class GithubConnector {
const { number: prNumber = 0 } = this.githubData.pullRequest;
const recentBody = await this.getLatestPRDescription({ repo, owner, number: this.githubData.pullRequest.number });

const nextBody = getPRDescription(recentBody, buildPRDescription(details))
if (nextBody === recentBody) {
console.info('edit would not change ticket body')
return undefined
}
console.log('diff', { nextBody, recentBody })
const prData: RestEndpointMethodTypes['pulls']['update']['parameters'] = {
owner,
repo,
pull_number: prNumber,
body: getPRDescription(recentBody, buildPRDescription(details)),
body: nextBody,
};

return await this.octokit.rest.pulls.update(prData);
Expand Down
7 changes: 3 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export const getPRDescription = (oldBody: string, details: string): string => {
const rg = new RegExp(`${hiddenMarkerStartRg}([\\s\\S]+)${hiddenMarkerEndRg}`, 'igm');
const bodyWithoutJiraDetails = (oldBody ?? '').replace(rg, '');

return `${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
return `${HIDDEN_MARKER_START}
${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${details}
${HIDDEN_MARKER_END}
${bodyWithoutJiraDetails}`;
${HIDDEN_MARKER_END}${bodyWithoutJiraDetails}`;
};

export const buildPRDescription = (details: JIRADetails) => {
Expand Down