Skip to content

Commit 9a5fc38

Browse files
committed
Add support for docker hub actions
1 parent 17e4e30 commit 9a5fc38

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

e2e/fixtures/.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ jobs:
1313
- uses: actions/upload-artifact@master
1414
# @OctoLinkerResolve(https://github.com/github/codeql-action/tree/main/init)
1515
- uses: github/codeql-action/init@v1
16+
# @OctoLinkerResolve(https://hub.docker.com/_/alpine)
17+
- uses: docker://alpine:3.8
18+
# @OctoLinkerResolve(https://hub.docker.com/r/github/super-linter)
19+
- uses: docker://github/super-linter:3.10.0

packages/plugin-docker/index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ import {
44
} from '@octolinker/helper-grammar-regex-collection';
55
import relativeFile from '@octolinker/resolver-relative-file';
66

7+
export function dockerHubUrl(target) {
8+
let isOfficial = true;
9+
const imageName = target.split(':')[0];
10+
11+
if (target.includes('/')) {
12+
isOfficial = false;
13+
}
14+
15+
return `https://hub.docker.com/${isOfficial ? '_' : 'r'}/${imageName}`;
16+
}
17+
718
export default {
819
name: 'Docker',
920

1021
resolve(path, [target]) {
11-
let isOffical = true;
12-
const imageName = target.split(':')[0];
13-
14-
if (target.includes('/')) {
15-
isOffical = false;
16-
}
17-
18-
return [
19-
relativeFile({ path, target }),
20-
`https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`,
21-
];
22+
return [relativeFile({ path, target }), dockerHubUrl(target)];
2223
},
2324

2425
getPattern() {

packages/plugin-github-actions/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { join } from 'path';
22
import { GITHUB_ACTIONS } from '@octolinker/helper-grammar-regex-collection';
3+
import { dockerHubUrl } from '@octolinker/plugin-docker';
4+
5+
const DOCKER_SOURCE = 'docker://';
36

47
export default {
58
name: 'GitHubActions',
@@ -9,6 +12,12 @@ export default {
912
return '';
1013
}
1114

15+
if (target.startsWith(DOCKER_SOURCE)) {
16+
const image = target.substring(DOCKER_SOURCE.length);
17+
18+
return dockerHubUrl(image);
19+
}
20+
1221
if (target.startsWith('.')) {
1322
const [, org, repo, , sha] = path.split('/');
1423

packages/plugin-github-actions/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"license": "MIT",
77
"main": "./index.js",
88
"dependencies": {
9-
"@octolinker/helper-grammar-regex-collection": "1.0.0"
9+
"@octolinker/helper-grammar-regex-collection": "1.0.0",
10+
"@octolinker/plugin-docker": "1.0.0"
1011
}
1112
}

0 commit comments

Comments
 (0)