This repository was archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (39 loc) · 1.61 KB
/
index.js
File metadata and controls
44 lines (39 loc) · 1.61 KB
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
38
39
40
41
42
43
44
'use strict'
const validate = require('./validate')
exports.post = post
function post ({
token = process.env.GH_STATUS_TOKEN || process.env.GH_TOKEN,
sha = process.env.CIRCLE_SHA1 || process.env.TRAVIS_PULL_REQUEST_SHA || process.env.TRAVIS_COMMIT || process.env.CI_COMMIT_ID,
owner = process.env.CIRCLE_PROJECT_USERNAME || extractSlug(process.env.TRAVIS_REPO_SLUG, 0) || extractSlug(process.env.CI_REPO_NAME, 0),
repo = process.env.CIRCLE_PROJECT_REPONAME || extractSlug(process.env.TRAVIS_REPO_SLUG, 1) || extractSlug(process.env.CI_REPO_NAME, 1),
state,
context,
description,
url,
rootURL = process.env.GITHUB_API || undefined
}) {
var validStates = ['pending', 'success', 'error', 'failure']
validate(
[token, 'GitHub token not configured (use GH_STATUS_TOKEN env var)'],
[sha, 'Unable to detect current build’s SHA'],
[owner, 'Unable to detect repository owner'],
[repo, 'Unable to detect repository name'],
[typeof state === 'string', 'state must be given'],
[typeof context === 'string', 'context must be given'],
[typeof description === 'string', 'description must be given'],
[!url || typeof url === 'string', 'url must be a string'],
[validStates.indexOf(state) >= 0, 'Invalid state (allowed: ' + state + ')']
)
const targetUrl = url
var Octokat = require('octokat')
var octo = new Octokat({ token: token, rootURL: rootURL })
return octo.repos(owner, repo).statuses(sha).create({
state: state,
context: context,
description: description,
target_url: targetUrl || undefined
})
}
function extractSlug (str, i) {
return str && str.split('/')[i]
}