Skip to content

Commit e120766

Browse files
committed
add fix-readme-badges boost example
1 parent 6901ffd commit e120766

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/** @type {import('@/lib/Boost').BoostScriptHandler} */
2+
module.exports.handler = async function ({
3+
boost, repository, git, libs, tools
4+
}) {
5+
let filename = repository.path + '/README.md';
6+
7+
if (!libs.fs.existsSync(filename)) {
8+
boost.log('stopping, no readme found');
9+
return true;
10+
}
11+
12+
boost.log('checking readme: ' + libs.path.basename(filename));
13+
14+
let fileContent = tools.readfile(filename);
15+
16+
if (!fileContent.includes('img.shields.io/github/workflow/status/')) {
17+
boost.log('stopping, no broken workflow badge found');
18+
return true;
19+
}
20+
21+
const workflowNameMatches = fileContent.match(/img\.shields\.io\/github\/workflow\/status\/[^/]+\/[^/]+\/([^?]+)/);
22+
23+
if (!workflowNameMatches) {
24+
boost.log('stopping, no workflow name found');
25+
return true;
26+
}
27+
28+
fileContent = fileContent.replaceAll('img.shields.io/github/workflow/status/', 'img.shields.io/github/actions/workflow/status/');
29+
fileContent = fileContent.replaceAll(`/status/${workflowNameMatches[1]}`, `/status/${libs.path.basename(boost.state.testWorkflowFile)}`);
30+
31+
boost.log(`Updated badge url`);
32+
33+
tools.writefile(filename, fileContent);
34+
boost.changedFiles.push(filename);
35+
36+
await git.add(filename);
37+
await git.commit(`fix readme badge`);
38+
39+
return true;
40+
};
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const findTestWorkflow = async function ({
2+
boost, git, libs, repository, tools
3+
}) {
4+
boost.log('finding tests workflow...');
5+
6+
if (typeof boost.state.testWorkflowFile === 'string' && boost.state.testWorkflowFile.length > 0) {
7+
boost.log('found tests workflow');
8+
return boost.state.testWorkflowFile;
9+
}
10+
11+
boost.state.testWorkflowFile = '';
12+
13+
for (const file of libs.fs.readdirSync(repository.path + '/.github/workflows', { encoding: 'utf-8', withFileTypes: true })) {
14+
if (file.isDirectory()) {
15+
continue;
16+
}
17+
18+
if (file.name.endsWith('.yml') || file.name.endsWith('.yaml')) {
19+
const data = tools.readfile(repository.path + '/.github/workflows/' + file.name);
20+
if (data.includes('test') && (data.includes('phpunit') || data.includes('pest'))) {
21+
boost.log('found tests workflow ' + file.name);
22+
boost.state.testWorkflowFile = repository.path + '/.github/workflows/' + file.name;
23+
return boost.state.testWorkflowFile;
24+
}
25+
}
26+
}
27+
28+
boost.log('could not find tests workflow');
29+
return false;
30+
};
31+
32+
/** @type {import('@/lib/Boost').BoostScriptHandler} */
33+
module.exports.handler = async function (params) {
34+
params.boost.log('initializing boost...');
35+
36+
params.boost.state.testWorkflowFile = '';
37+
38+
await findTestWorkflow(params);
39+
40+
params.boost.log('finished initializing boost');
41+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Summary
2+
3+
This PR fixes a broken badge in the README.
4+
5+
_id:{{boost.id}}/v{{boost.version}}_

examples/fix-readme-badges/boost.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('@/types/BoostConfiguration').BoostConfiguration} */
2+
module.exports.default = {
3+
id: 'fix-readme-badges',
4+
version: '1.0.0',
5+
repository_limits: {
6+
max_runs_per_version: 1,
7+
minutes_between_runs: 60,
8+
},
9+
pull_request: {
10+
title: 'Fix Readme badges',
11+
body: 'pull-request-body.edge.md',
12+
branch: 'fix-readme-badges',
13+
},
14+
scripts: {
15+
parallel: true,
16+
files: [ 'fix-readme-badge.js' ],
17+
},
18+
};

0 commit comments

Comments
 (0)