-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const invariant = require('invariant')
const Octokit = require('@octokit/rest')
const env = require('require-env')
const {parse} = require('url')
module.exports = function createStatus(props) {
const {
// XXX This is a workaround for `act`, which initializes
// GITHUB_REPOSITORY as the fully-qualified git remote URL
// rather than just the "owner/repo" slug.
repository = getURLPath(env.require('GITHUB_REPOSITORY')),
sha = env.require('GITHUB_SHA'),
state = env.require('GITHUB_ACTION_STATE'),
context = env.require('GITHUB_ACTION_CONTEXT'),
description = env.require('GITHUB_ACTION_DESC'),
url = env.require('GITHUB_ACTION_TARGET_URL'),
token = env.require('GITHUB_TOKEN')
} = props
const [owner, repo] = repository.split('/')
const github = new Octokit({auth: `token ${token}`})
return github.repos.createStatus({
owner,
repo,
sha,
context,
state,
description,
target_url: url
})
}
function getURLPath(str) {
const {path} = parse(str)
return path.replace(/^\//, '')
}