Skip to content

Commit

Permalink
fix: remove checkbox hints + checkbox formatting for bitbucket via re…
Browse files Browse the repository at this point in the history
…adOnlyIssueBody() transformer (#3765)
  • Loading branch information
psyb0t authored and rarkins committed May 21, 2019
1 parent dbb1332 commit 05ec931
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/platform/bitbucket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const api = require('./bb-got-wrapper');
const utils = require('./utils');
const hostRules = require('../../util/host-rules');
const GitStorage = require('../git/storage');
const { readOnlyIssueBody } = require('../utils/read-only-issue-body');
const { appSlug } = require('../../config/app-strings');

let config = {};
Expand Down Expand Up @@ -367,7 +368,9 @@ async function ensureIssue(title, body) {
await api.put(
`/2.0/repositories/${config.repository}/issues/${issue.id}`,
{
body: { content: { raw: body, markup: 'markdown' } },
body: {
content: { raw: readOnlyIssueBody(body), markup: 'markdown' },
},
}
);
return 'updated';
Expand All @@ -377,7 +380,7 @@ async function ensureIssue(title, body) {
await api.post(`/2.0/repositories/${config.repository}/issues`, {
body: {
title,
content: { raw: body, markup: 'markdown' },
content: { raw: readOnlyIssueBody(body), markup: 'markdown' },
},
});
return 'created';
Expand Down
12 changes: 12 additions & 0 deletions lib/platform/utils/read-only-issue-body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function readOnlyIssueBody(body) {
return body
.replace(' only once you click their checkbox below', '')
.replace(' unless you click a checkbox below', '')
.replace(' To discard all commits and start over, check the box below.', '')
.replace(/ Click (?:on |)a checkbox.*\./g, '')
.replace(/\[ ] <!-- \w*-branch.*-->/g, '');
}

module.exports = {
readOnlyIssueBody,
};
11 changes: 11 additions & 0 deletions test/platform/utils/_fixtures/issue-body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, check the box below.

- [ ] <!-- rebase-branch=renovate/docker-renovate-renovate-16.x -->[Update renovate/renovate Docker tag to v16.13.8](../pull/2)

## Closed/Ignored

These updates were closed unmerged and will not be recreated unless you click a checkbox below.

- [ ] <!-- recreate-branch=renovate/docker-renovate-renovate-16.10.8 -->[Update renovate/renovate:16.10.8 Docker digest to 6f9a209](../pull/1)
27 changes: 27 additions & 0 deletions test/platform/utils/read-only-issue-body.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require('fs');
const {
readOnlyIssueBody,
} = require('../../../lib/platform/utils/read-only-issue-body');

const issueBody = fs.readFileSync(
'test/platform/utils/_fixtures/issue-body.txt',
'utf8'
);

describe('platform/utils/read-only-issue-body', () => {
describe('.readOnlyIssueBody', () => {
it('removes all checkbox formatting', () => {
expect(readOnlyIssueBody(issueBody)).toEqual(
expect.not.stringContaining('[ ] <!--')
);
});

it('removes all checkbox-related instructions', () => {
expect(readOnlyIssueBody(issueBody)).toEqual(
expect.not.stringMatching(
/click (?:(?:on |)a|their) checkbox|check the box below/gi
)
);
});
});
});

0 comments on commit 05ec931

Please sign in to comment.