Skip to content

Commit 9adb620

Browse files
committed
fix(badge): support name that includes space
fix #2
1 parent 76f32d4 commit 9adb620

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

.github/workflows/test-quote.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "test quote space's"
2+
3+
on: [push, pull_request]
4+
env:
5+
CI: true
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- run: # none

src/github-actions-badge.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export const fetchRepositoryInfo = (): Promise<{ owner: string; repo: string }>
2525
};
2626
});
2727
};
28+
29+
// FIXME: GitHub Action Spec does not define the query
30+
const encodeWorkflowNameQuery = (name: string) => {
31+
return name.replace(/\s/g, "+");
32+
};
2833
export const generate = (options: generateOptions): string => {
2934
const ymlList = glob.sync(path.join(options.cwd, ".github/workflows/*"), {
3035
dot: true
@@ -38,6 +43,6 @@ export const generate = (options: generateOptions): string => {
3843
}).map(workflowName => {
3944
// --format "markdown"
4045
// https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg
41-
return `[![Actions Status](https://github.com/${options.owner}/${options.repo}/workflows/${encodeURIComponent(workflowName)}/badge.svg)](https://github.com/${options.owner}/${options.repo}/actions?query=workflow%3A${encodeURIComponent(workflowName)})`;
46+
return `[![Actions Status](https://github.com/${options.owner}/${options.repo}/workflows/${encodeURIComponent(workflowName)}/badge.svg)](https://github.com/${options.owner}/${options.repo}/actions?query=workflow%3A"${encodeWorkflowNameQuery(workflowName)}")`;
4247
}).join("\n");
4348
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Make draft release package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'draft/v*' # e.g. draft/v2_6_4
7+
repository_dispatch:
8+
types:
9+
- "refs/tags/v*" # e.g. refs/tags/v2_6_4
10+
11+
jobs:
12+
dump-context:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- run: env | sort

test/github-actions-badge.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ describe("github-actions-badge", function() {
1313
assert.strictEqual(codes, `[![Actions Status](https://github.com/azu/github-actions-badge/workflows/ci/badge.svg)](https://github.com/azu/github-actions-badge/actions?query=workflow%3Aci)`
1414
);
1515
});
16+
it("should return badge codes that replace includes-space with +", () => {
17+
const codes = generate({
18+
owner: "ruby",
19+
repo: "actions",
20+
cwd: path.join(__dirname, "fixtures/includes-space"),
21+
format: "markdown"
22+
});
23+
assert.strictEqual(codes, `[![Actions Status](https://github.com/ruby/actions/workflows/Make%20draft%20release%20package/badge.svg)](https://github.com/ruby/actions/actions?query=workflow%3A"Make+draft+release+package")`
24+
);
25+
});
1626
});

0 commit comments

Comments
 (0)