Skip to content

Commit 4c041ba

Browse files
authored
host the lint details ourselves. (#6)
* move files into src * use markdown
1 parent f762686 commit 4c041ba

12 files changed

+89
-24
lines changed

__tests__/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const commitlintbot = require('../');
1+
const commitlintbot = require('../src/index');
22

33
test.skip('commitlint should not throw', async () => {
44
const prData = {

__tests__/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const lint = require('../lint');
1+
const lint = require('../src/lint');
22

33
test('commitlint should work', async () => {
44

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"test": "jest",
12-
"start": "node --trace-warnings server.js"
12+
"start": "node --trace-warnings src/server.js"
1313
},
1414
"files": [
1515
"dist"
@@ -23,6 +23,7 @@
2323
"commitlint-config-cz": "^0.5.0",
2424
"express": "^4.14.0",
2525
"github-build": "^1.2.0",
26+
"marked": "^0.3.19",
2627
"promise-queue": "^2.2.3",
2728
"raven": "^2.2.1",
2829
"require-from-string": "^2.0.1"
File renamed without changes.

github.js renamed to src/github.js

File renamed without changes.

index.js renamed to src/index.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ Raven.config(
77
).install();
88

99
const requireFromString = require('require-from-string');
10-
const lhClintConfig = require('./lighthouse.commitlint.config');
1110
const {getPRTitle, getFileContents} = require('./github');
1211

1312
const lint = require('./lint');
1413

1514
const MAXIMUM_STATUS_LENGTH = 140;
1615
const czConfigFilename = `.cz-config.js`;
17-
const czConfigPath = `${__dirname}/${czConfigFilename}`;
16+
const czConfigPath = `${__dirname}/../${czConfigFilename}`;
1817
const clintConfigFilename = 'commitlint.config.js';
1918

2019
const baseGithubData = {
2120
token: process.env.GHTOKEN, // (github oauth token: https://developer.github.com/v3/oauth)
22-
label: 'commitlint'
21+
label: 'pr title lint'
2322
};
2423

2524
async function init(prData) {
@@ -42,7 +41,7 @@ async function init(prData) {
4241
lintOpts.clintConfig = requireFromString(clintConfigContent);
4342
// FIXME: remove this hack for backwards compatibility
4443
} else if (githubData.repo.includes('lighthouse')) {
45-
lintOpts.clintConfig = lhClintConfig;
44+
lintOpts.clintConfig = require('./lighthouse.commitlint.config'); // where even is this
4645
}
4746

4847
// FIXME: can't write to disk on now.sh. will have to find a workaround.
@@ -89,25 +88,25 @@ async function init(prData) {
8988
return {status, data: {error}};
9089
}
9190

92-
function generateURL(prTitle, reportArr) {
93-
const titlePrefix = `Commit message:
91+
92+
}
93+
94+
module.exports = init;
95+
96+
function generateURL(prTitle, reportArr) {
97+
const outputStr = `
98+
### Pull request title
9499
> ${prTitle}
95100
96-
commitlint results:
97-
`;
98-
const link = `
101+
### Commitlint results
99102
100-
Expected PR title format is: {type}({optional-scope}): {subject}
103+
* ${reportArr.join('\n* ')}
101104
102-
See commitlint rules: https://github.com/marionebl/commitlint/blob/master/docs/reference-rules.md`;
103-
const preparedString = `${titlePrefix}${reportArr.join('
')}`
104-
.replace(//g, '✖')
105-
.replace(//g, '✔')
106-
.replace(//g, '⚠');
107-
return `https://unhtml.appspot.com/escape?%3Cpre%3E${encodeURIComponent(
108-
preparedString
109-
)}%3C/pre%3E${encodeURIComponent(link)}`;
110-
}
105+
Expected PR title format is: \`{type}({optional-scope}): {subject}\`
106+
107+
[Full docs of commitlint rules](https://github.com/marionebl/commitlint/blob/master/docs/reference-rules.md)
108+
`;
109+
110+
return `https://commitlintbot.now.sh/details/?msg=${encodeURIComponent(outputStr)}`;
111111
}
112112

113-
module.exports = init;
File renamed without changes.
File renamed without changes.

lint.js renamed to src/lint.js

File renamed without changes.

server.js renamed to src/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const bodyParser = require('body-parser');
22
const server = require('express')();
33
const Queue = require('promise-queue');
4-
const {version} = require('./package.json');
4+
const {version} = require('../package.json');
55
const commitlintbot = require('./');
66

77
const Raven = require('raven');
8+
const viewDetails = require('./view-details');
89

910
const log = console;
1011

@@ -14,6 +15,8 @@ const queue = new Queue(1, process.env.STAGE_CI_MAX_QUEUE || 100);
1415
// github's webhook MUST use `application/json`
1516
server.use(bodyParser.json());
1617

18+
server.get('/details/', viewDetails);
19+
1720
server.get('/', (request, response) => {
1821
response.json({version, queue});
1922
});

0 commit comments

Comments
 (0)