@pansycareful/github-helper 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -0
- package/scripts/postinstall.js +12 -0
- package/src/client.js +61 -0
- package/src/index.js +13 -0
- package/src/issues.js +27 -0
- package/src/pulls.js +28 -0
- package/src/repos.js +21 -0
- package/src/users.js +13 -0
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pansycareful/github-helper",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A helper utility for interacting with the GitHub API",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"postinstall": "node scripts/postinstall.js",
|
|
8
|
+
"test": "node --test test/"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"github",
|
|
12
|
+
"api",
|
|
13
|
+
"helper",
|
|
14
|
+
"git",
|
|
15
|
+
"repository",
|
|
16
|
+
"issues",
|
|
17
|
+
"pull-requests"
|
|
18
|
+
],
|
|
19
|
+
"author": "pansy",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"files": [
|
|
22
|
+
"src/",
|
|
23
|
+
"scripts/"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const MESSAGE = `
|
|
6
|
+
=====================================
|
|
7
|
+
Thanks for installing github-helper!
|
|
8
|
+
Get started: https://github.com/github-helper
|
|
9
|
+
=====================================
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
console.log(MESSAGE);
|
package/src/client.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const https = require("https");
|
|
4
|
+
|
|
5
|
+
const BASE_URL = "api.github.com";
|
|
6
|
+
|
|
7
|
+
function request(method, path, { token, body } = {}) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const headers = {
|
|
10
|
+
"User-Agent": "github-helper",
|
|
11
|
+
Accept: "application/vnd.github+json",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
if (token) {
|
|
15
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (body) {
|
|
19
|
+
headers["Content-Type"] = "application/json";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const options = {
|
|
23
|
+
hostname: BASE_URL,
|
|
24
|
+
path,
|
|
25
|
+
method,
|
|
26
|
+
headers,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const req = https.request(options, (res) => {
|
|
30
|
+
let data = "";
|
|
31
|
+
res.on("data", (chunk) => (data += chunk));
|
|
32
|
+
res.on("end", () => {
|
|
33
|
+
if (res.statusCode >= 400) {
|
|
34
|
+
const error = new Error(`GitHub API error: ${res.statusCode}`);
|
|
35
|
+
error.status = res.statusCode;
|
|
36
|
+
try {
|
|
37
|
+
error.response = JSON.parse(data);
|
|
38
|
+
} catch {
|
|
39
|
+
error.response = data;
|
|
40
|
+
}
|
|
41
|
+
return reject(error);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
resolve(data ? JSON.parse(data) : null);
|
|
45
|
+
} catch {
|
|
46
|
+
resolve(data);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
req.on("error", reject);
|
|
52
|
+
|
|
53
|
+
if (body) {
|
|
54
|
+
req.write(JSON.stringify(body));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
req.end();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { request };
|
package/src/index.js
ADDED
package/src/issues.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { request } = require("./client");
|
|
4
|
+
|
|
5
|
+
function list(owner, repo, options = {}) {
|
|
6
|
+
return request("GET", `/repos/${owner}/${repo}/issues`, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function get(owner, repo, number, options = {}) {
|
|
10
|
+
return request("GET", `/repos/${owner}/${repo}/issues/${number}`, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function create(owner, repo, data, options = {}) {
|
|
14
|
+
return request("POST", `/repos/${owner}/${repo}/issues`, {
|
|
15
|
+
...options,
|
|
16
|
+
body: data,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function update(owner, repo, number, data, options = {}) {
|
|
21
|
+
return request("PATCH", `/repos/${owner}/${repo}/issues/${number}`, {
|
|
22
|
+
...options,
|
|
23
|
+
body: data,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { list, get, create, update };
|
package/src/pulls.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { request } = require("./client");
|
|
4
|
+
|
|
5
|
+
function list(owner, repo, options = {}) {
|
|
6
|
+
return request("GET", `/repos/${owner}/${repo}/pulls`, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function get(owner, repo, number, options = {}) {
|
|
10
|
+
return request("GET", `/repos/${owner}/${repo}/pulls/${number}`, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function create(owner, repo, data, options = {}) {
|
|
14
|
+
return request("POST", `/repos/${owner}/${repo}/pulls`, {
|
|
15
|
+
...options,
|
|
16
|
+
body: data,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function merge(owner, repo, number, options = {}) {
|
|
21
|
+
return request(
|
|
22
|
+
"PUT",
|
|
23
|
+
`/repos/${owner}/${repo}/pulls/${number}/merge`,
|
|
24
|
+
options
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { list, get, create, merge };
|
package/src/repos.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { request } = require("./client");
|
|
4
|
+
|
|
5
|
+
function list(username, options = {}) {
|
|
6
|
+
return request("GET", `/users/${username}/repos`, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function get(owner, repo, options = {}) {
|
|
10
|
+
return request("GET", `/repos/${owner}/${repo}`, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function create(data, options = {}) {
|
|
14
|
+
return request("POST", "/user/repos", { ...options, body: data });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function remove(owner, repo, options = {}) {
|
|
18
|
+
return request("DELETE", `/repos/${owner}/${repo}`, options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { list, get, create, remove };
|
package/src/users.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { request } = require("./client");
|
|
4
|
+
|
|
5
|
+
function get(username, options = {}) {
|
|
6
|
+
return request("GET", `/users/${username}`, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getAuthenticated(options = {}) {
|
|
10
|
+
return request("GET", "/user", options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { get, getAuthenticated };
|