Skip to content

Commit b66503a

Browse files
author
Peter Grainger
committed
initial commit
1 parent 3d84f6d commit b66503a

10 files changed

+798
-71
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ typings/
8989

9090
# DynamoDB Local files
9191
.dynamodb/
92+
93+
lib/

.vscode/launch.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Jest All",
8+
"program": "${workspaceFolder}/node_modules/.bin/jest",
9+
"args": ["--runInBand"],
10+
"console": "integratedTerminal",
11+
"internalConsoleOptions": "neverOpen",
12+
"disableOptimisticBPs": true,
13+
"windows": {
14+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
15+
}
16+
},
17+
{
18+
"type": "node",
19+
"request": "launch",
20+
"name": "Jest Current File",
21+
"program": "${workspaceFolder}/node_modules/.bin/jest",
22+
"args": [
23+
"${fileBasenameNoExtension}",
24+
"--config",
25+
"jest.config.js"
26+
],
27+
"console": "integratedTerminal",
28+
"internalConsoleOptions": "neverOpen",
29+
"disableOptimisticBPs": true,
30+
"windows": {
31+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
32+
}
33+
}
34+
]
35+
}

__tests__/context.json

+472
Large diffs are not rendered by default.

__tests__/create-branch.test.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {createBranch} from '../src/create-branch'
2+
import { readFileSync } from 'fs';
3+
4+
describe('Create a branch based on the input', () => {
5+
6+
let githubMock;
7+
let contextMock;
8+
let branch = 'release-v1';
9+
let octokitMock;
10+
11+
beforeEach(()=> {
12+
octokitMock = {
13+
git: {
14+
createRef: jest.fn()
15+
}
16+
}
17+
})
18+
19+
beforeEach(()=> {
20+
githubMock = jest.fn().mockImplementation(() => {
21+
return octokitMock;
22+
})
23+
})
24+
25+
beforeEach(() => {
26+
contextMock = JSON.parse(readFileSync('__tests__/context.json', 'utf8'))
27+
})
28+
29+
beforeEach(() => {
30+
process.env.GITHUB_TOKEN = 'token'
31+
})
32+
33+
34+
it('Create new branch', async () => {
35+
await createBranch(githubMock, contextMock, branch)
36+
expect(octokitMock.git.createRef).toHaveBeenCalledWith({
37+
ref: 'refs/heads/release-v1',
38+
sha: 'ebb4992dc72451c1c6c99e1cce9d741ec0b5b7d7'
39+
})
40+
});
41+
42+
it('fails if github token isn\'t defined', async() => {
43+
delete process.env.GITHUB_TOKEN
44+
expect.assertions(1);
45+
try {
46+
await createBranch(githubMock, contextMock, branch)
47+
} catch (error) {
48+
expect(error).toEqual(new ReferenceError('No token defined in the environment variables'))
49+
}
50+
})
51+
});

__tests__/main.test.ts

-3
This file was deleted.

action.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: 'Your name here'
2-
description: 'Provide a description here'
3-
author: 'Your name or organization here'
1+
name: 'Create Branch'
2+
description: 'Creates a branch'
3+
author: 'Peter Grainger (peter@grainger)'
44
inputs:
5-
myInput: # change this
6-
description: 'input description here'
7-
default: 'default value if applicable'
5+
branch:
6+
description: 'The branch to create'
7+
default: 'release-candidate'
88
runs:
99
using: 'node12'
1010
main: 'lib/main.js'

0 commit comments

Comments
 (0)