Skip to content

Commit

Permalink
Add GitHub Action support (OctoLinker#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck authored Nov 10, 2019
1 parent b46de9c commit b196ff8
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
13 changes: 13 additions & 0 deletions e2e/fixtures/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Test"
on: ['push']

jobs:
test:
runs-on: ubuntu-latest
steps:
# @OctoLinkerResolve(https://github.com/actions/checkout)
- uses: actions/checkout@v1
# @OctoLinkerResolve(https://github.com/actions/setup-node)
- uses: actions/setup-node
# @OctoLinkerResolve(https://github.com/actions/upload-artifact)
- uses: actions/upload-artifact@master
1 change: 1 addition & 0 deletions packages/core/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export { default as Rust } from '@octolinker/plugin-rust';
export { default as Sass } from '@octolinker/plugin-sass';
export { default as TypeScript } from '@octolinker/plugin-typescript';
export { default as Vim } from '@octolinker/plugin-vim';
export { default as GitHubActions } from '@octolinker/plugin-github-actions';
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@octolinker/plugin-dot-net": "1.0.0",
"@octolinker/plugin-dot-net-core": "1.0.0",
"@octolinker/plugin-gemfile-manifest": "1.0.0",
"@octolinker/plugin-github-actions": "1.0.0",
"@octolinker/plugin-go": "1.0.0",
"@octolinker/plugin-haskell": "1.0.0",
"@octolinker/plugin-homebrew-manifest": "1.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/helper-grammar-regex-collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export const NET_PACKAGE = regex`
.*/>
`;

export const GITHUB_ACTIONS = regex`
uses:\s(?<$1>[^@\s]+)
`;

export const JAVA_IMPORT = regex`
${diffSigns}
import
Expand Down
8 changes: 8 additions & 0 deletions packages/helper-grammar-regex-collection/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ const fixtures = {
'< DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />',
],
},
GITHUB_ACTIONS: {
valid: [
['uses: foo/bar', ['foo/bar']],
['uses: foo/bar@v1', ['foo/bar']],
['uses: foo/bar@master', ['foo/bar']],
],
invalid: [],
},
};

function fixturesIterator(fixturesList, next) {
Expand Down
20 changes: 20 additions & 0 deletions packages/plugin-github-actions/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from 'assert';
import GiHubActions from '../index';

describe('GiHubActions', () => {
const target = 'foo/bar';

it('resolves link when file is within .github/workflows', () => {
assert.deepEqual(
GiHubActions.resolve('/octo/cat/.github/workflows/dog.yml', [target]),
'{BASE_URL}/foo/bar',
);
});

it('does not resolves link when file is not within .github/workflows', () => {
assert.deepEqual(
GiHubActions.resolve('/octo/cat/.github/dog.yml', [target]),
'',
);
});
});
24 changes: 24 additions & 0 deletions packages/plugin-github-actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { GITHUB_ACTIONS } from '@octolinker/helper-grammar-regex-collection';

export default {
name: 'GitHubActions',

resolve(path, [target]) {
if (!path.includes('.github/workflows')) {
return '';
}

return `{BASE_URL}/${target}`;
},

getPattern() {
return {
pathRegexes: [/\.ya?ml$/],
githubClasses: [],
};
},

getLinkRegexes() {
return GITHUB_ACTIONS;
},
};
11 changes: 11 additions & 0 deletions packages/plugin-github-actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@octolinker/plugin-github-actions",
"version": "1.0.0",
"description": "",
"repository": "https://github.com/octolinker/octolinker/tree/master/packages/plugin-github-actions",
"license": "MIT",
"main": "./index.js",
"dependencies": {
"@octolinker/helper-grammar-regex-collection": "1.0.0"
}
}

0 comments on commit b196ff8

Please sign in to comment.