-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
42 lines (41 loc) · 1.05 KB
/
github.js
File metadata and controls
42 lines (41 loc) · 1.05 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
const { Octokit } = require("@octokit/rest")
/**
* Update a commit status in GitHub
*
* @param {String} auth - The GitHub personal token
* @param {String} sha - The GitHub commit hash that will be updated
* @param {String} state - The status to set
* @param {String} description - The Rich Media description
* @param {String} target_url - The URL to add to the commit message
*
* @returns Promise
*/
module.exports = {
updateGithubStatus: async ({
auth,
sha,
state,
description,
// eslint-disable-next-line camelcase
target_url,
}) => {
try {
const octokit = new Octokit({ auth })
const [owner, repoWithGit] = process.env.REPOSITORY_URL.split(
"github.com/"
)[1].split("/")
const repo = repoWithGit.split('.git')[0]
await octokit.request("POST /repos/{owner}/{repo}/statuses/{sha}", {
owner,
repo,
sha,
state,
description,
context: "Ghost Inspector E2E Tests",
target_url,
})
} catch (error) {
console.log(error)
}
}
}