Skip to content

Commit

Permalink
feat: clean title
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Dec 4, 2018
1 parent 99d18d8 commit d3a7bf2
Show file tree
Hide file tree
Showing 6 changed files with 1,708 additions and 52 deletions.
18 changes: 17 additions & 1 deletion .eslintrc.json
Expand Up @@ -8,5 +8,21 @@
}
],
"complexity": "off"
}
},
"overrides": [
{
"files": ["lib/**/*.test.js", "lib/__tests__/**/*.js"],
"env": {
"jest": true
},
"rules": {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
}
]
}
5 changes: 2 additions & 3 deletions lib/index.js
Expand Up @@ -3,6 +3,7 @@
'use strict';

const { obtainRepoContext } = require('./context/repoContext');
const cleanTitle = require('./utils/cleanTitle');
const config = require('./teamconfig');

// const getConfig = require('probot-config')
Expand Down Expand Up @@ -35,9 +36,7 @@ module.exports = (app) => {
if (!repoContext.config.trimTitle) return;

const pr = context.payload.pull_request;
const title = pr.title
.trim()
.replace(/[\s-]+\[?\s*(ONK-\d+)\s*]?\s*$/, ' $1');
const title = cleanTitle(pr.title);

if (pr.title !== title) {
context.github.issues.update(
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/cleanTitle.js
@@ -0,0 +1,7 @@
'use strict';

module.exports = (title) =>
title
.trim()
.replace(/[\s-]+\[?\s*(ONK-\d+)\s*]?\s*$/, ' $1')
.replace(/^([A-Za-z]+)[/:]\s*/, (s, arg1) => `${arg1.toLowerCase()}: `);
25 changes: 25 additions & 0 deletions lib/utils/cleanTitle.test.js
@@ -0,0 +1,25 @@
'use strict';

const cleanTitle = require('./cleanTitle');

it('should clean dash before ONK', () => {
expect(cleanTitle('feat: add something - ONK-1234')).toBe(
'feat: add something ONK-1234'
);
});

it('should clean space before ONK', () => {
expect(cleanTitle('feat: add something ONK-1234')).toBe(
'feat: add something ONK-1234'
);
});

it('should clean dash and space before ONK', () => {
expect(cleanTitle('feat: add something - ONK-1234')).toBe(
'feat: add something ONK-1234'
);
});

it('should clean uppercase and slash', () => {
expect(cleanTitle('Feat/add something')).toBe('feat: add something');
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -68,6 +68,7 @@
"eslint-plugin-import": "2.14.0",
"eslint-plugin-node": "8.0.0",
"husky": "1.2.0",
"jest": "^23.6.0",
"lint-staged": "8.1.0",
"localtunnel": "1.9.1",
"nodemon": "1.18.6",
Expand Down

0 comments on commit d3a7bf2

Please sign in to comment.