tigger 0.0.1 → 0.0.2

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.
Files changed (36) hide show
  1. package/bin/constants.js +19 -0
  2. package/bin/example/handler/alterIssue.js +30 -0
  3. package/bin/example/handler/commit.js +44 -0
  4. package/bin/example/handler/createComment.js +30 -0
  5. package/bin/example/handler/createIssue.js +28 -0
  6. package/bin/example/handler/editComment.js +32 -0
  7. package/bin/example/handler/editIssue.js +32 -0
  8. package/bin/example/handler/issue.js +26 -0
  9. package/bin/example/handler/issues.js +24 -0
  10. package/bin/example/handler/removeComment.js +30 -0
  11. package/bin/example/operation/alterIssue.js +29 -0
  12. package/bin/example/operation/createComment.js +29 -0
  13. package/bin/example/operation/createIssue.js +36 -0
  14. package/bin/example/operation/editComment.js +29 -0
  15. package/bin/example/operation/editIssue.js +29 -0
  16. package/bin/example/operation/getBaseTreeSHA.js +36 -0
  17. package/bin/example/operation/getComments.js +36 -0
  18. package/bin/example/operation/getIssue.js +35 -0
  19. package/bin/example/operation/getIssues.js +35 -0
  20. package/bin/example/operation/getLatestCommitSHA.js +36 -0
  21. package/bin/example/operation/postCommitSHA.js +35 -0
  22. package/bin/example/operation/postCommitTreeSHA.js +43 -0
  23. package/bin/example/operation/postMetaJSONFileContent.js +36 -0
  24. package/bin/example/operation/postReadmeFileContent.js +36 -0
  25. package/bin/example/operation/postUpdatedHead.js +29 -0
  26. package/bin/example/operation/removeComment.js +27 -0
  27. package/bin/example.js +24 -0
  28. package/bin/uris.js +31 -0
  29. package/bin/utilities/comment.js +68 -0
  30. package/bin/utilities/commit.js +115 -0
  31. package/bin/utilities/headers.js +43 -0
  32. package/bin/utilities/issue.js +87 -0
  33. package/bin/utilities/repository.js +39 -0
  34. package/bin/utilities/request.js +94 -0
  35. package/index.js +11 -0
  36. package/package.json +4 -3
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ const { commitUtilities } = require("../../.."); ///
4
+
5
+ const { commitTreeSHAPostRequest } = commitUtilities;
6
+
7
+ function postCommitTreeSHAOperation(next, done, context) {
8
+ const { repository, baseTreeSHA, readmeFileSHA, readmeFilePath, metaJSONFileSHA, metaJSONFilePath, userAgent, gitHubAccessToken } = context,
9
+ fileShAs = [
10
+ readmeFileSHA,
11
+ metaJSONFileSHA
12
+ ],
13
+ filePaths = [
14
+ readmeFilePath,
15
+ metaJSONFilePath
16
+ ];
17
+
18
+ commitTreeSHAPostRequest(repository, baseTreeSHA, fileShAs, filePaths, userAgent, gitHubAccessToken, (error, json) => {
19
+ if (error) {
20
+ done();
21
+
22
+ return;
23
+ }
24
+
25
+ const { sha = null } = json;
26
+
27
+ if (sha === null) {
28
+ done();
29
+
30
+ return;
31
+ }
32
+
33
+ const commitTreeSHA = sha; ///
34
+
35
+ Object.assign(context, {
36
+ commitTreeSHA
37
+ });
38
+
39
+ next();
40
+ });
41
+ }
42
+
43
+ module.exports = postCommitTreeSHAOperation;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ const { commitUtilities } = require("../../.."); ///
4
+
5
+ const { contentBlobSHAPostRequest } = commitUtilities;
6
+
7
+ function postMetaJSONFileContentOperation(next, done, context) {
8
+ const { repository, userAgent, gitHubAccessToken, metaJSONFileContent } = context,
9
+ content = metaJSONFileContent; ///
10
+
11
+ contentBlobSHAPostRequest(repository, content, userAgent, gitHubAccessToken, (error, json) => {
12
+ if (error) {
13
+ done();
14
+
15
+ return;
16
+ }
17
+
18
+ const { sha = null } = json;
19
+
20
+ if (sha === null) {
21
+ done();
22
+
23
+ return;
24
+ }
25
+
26
+ const metaJSONFileSHA = sha;
27
+
28
+ Object.assign(context, {
29
+ metaJSONFileSHA
30
+ });
31
+
32
+ next();
33
+ });
34
+ }
35
+
36
+ module.exports = postMetaJSONFileContentOperation;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ const { commitUtilities } = require("../../.."); ///
4
+
5
+ const { contentBlobSHAPostRequest } = commitUtilities;
6
+
7
+ function postReadmeFileContentOperation(next, done, context) {
8
+ const { repository, userAgent, gitHubAccessToken, readmeFileContent } = context,
9
+ content = readmeFileContent; ///
10
+
11
+ contentBlobSHAPostRequest(repository, content, userAgent, gitHubAccessToken, (error, json) => {
12
+ if (error) {
13
+ done();
14
+
15
+ return;
16
+ }
17
+
18
+ const { sha = null } = json;
19
+
20
+ if (sha === null) {
21
+ done();
22
+
23
+ return;
24
+ }
25
+
26
+ const readmeFileSHA = sha; ///
27
+
28
+ Object.assign(context, {
29
+ readmeFileSHA
30
+ });
31
+
32
+ next();
33
+ });
34
+ }
35
+
36
+ module.exports = postReadmeFileContentOperation;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ const { commitUtilities } = require("../../.."); ///
4
+
5
+ const { updatedHeadPostRequest } = commitUtilities;
6
+
7
+ function postUpdatedHeadOperation(next, done, context) {
8
+ const { repository, commitSHA, userAgent, gitHubAccessToken } = context;
9
+
10
+ updatedHeadPostRequest(repository, commitSHA, userAgent, gitHubAccessToken, (error, json) => {
11
+ if (error) {
12
+ done();
13
+
14
+ return;
15
+ }
16
+
17
+ const { object = null } = json;
18
+
19
+ if (object === null) {
20
+ done();
21
+
22
+ return;
23
+ }
24
+
25
+ next();
26
+ });
27
+ }
28
+
29
+ module.exports = postUpdatedHeadOperation;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ const { commentUtilities } = require("../../.."); ///
4
+
5
+ const { removeCommentDeleteRequest } = commentUtilities;
6
+
7
+ function removeCommentOperation(next, done, context) {
8
+ const { repository, commentIdentifier, userAgent, gitHubAccessToken } = context;
9
+
10
+ removeCommentDeleteRequest(repository, commentIdentifier, userAgent, gitHubAccessToken, (error, string) => {
11
+ if (error) {
12
+ done();
13
+
14
+ return;
15
+ }
16
+
17
+ if (string !== "") {
18
+ done();
19
+
20
+ return;
21
+ }
22
+
23
+ next();
24
+ });
25
+ }
26
+
27
+ module.exports = removeCommentOperation;
package/bin/example.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ const issueHandler = require("./example/handler/issue"),
4
+ issuesHandler = require("./example/handler/issues"),
5
+ commitHandler = require("./example/handler/commit"),
6
+ editIssueHandler = require("./example/handler/editIssue"),
7
+ alterIssueHandler = require("./example/handler/alterIssue"),
8
+ createIssueHandler = require("./example/handler/createIssue"),
9
+ editCommentHandler = require("./example/handler/editComment"),
10
+ createCommentHandler = require("./example/handler/createComment"),
11
+ removeCommentHandler = require("./example/handler/removeComment");
12
+
13
+ const clientId = "...",
14
+ userAgent = "...",
15
+ repository = "...",
16
+ clientSecret = "...",
17
+ gitHubAccessToken = "...",
18
+ context = {
19
+ clientId,
20
+ userAgent,
21
+ repository,
22
+ clientSecret,
23
+ gitHubAccessToken
24
+ };
package/bin/uris.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ const SETTINGS_URI = "/settings",
4
+ LATEST_RELEASES_URI = "/", ///
5
+ GITHUB_USER_URI = "/user",
6
+ GITHUB_REPOS_URI = "/repos",
7
+ GITHUB_ISSUES_URI = "/issues",
8
+ GITHUB_COMMENTS_URI = "/comments",
9
+ GITHUB_GIT_TREES_URI = "/git/trees",
10
+ GITHUB_GIT_BLOBS_URI = "/git/blobs",
11
+ GITHUB_GIT_COMMITS_URI = "/git/commits",
12
+ GITHUB_ISSUES_COMMENTS_URI = "/issues/comments",
13
+ GITHUB_GIT_REFS_HEADS_MASTER_URI = "/git/refs/heads/master",
14
+ GITHUB_LOGIN_OAUTH_AUTHORIZE_URI = "/login/oauth/authorize",
15
+ GITHUB_LOGIN_OAUTH_ACCESS_TOKEN_URI = "/login/oauth/access_token";
16
+
17
+ module.exports = {
18
+ SETTINGS_URI,
19
+ LATEST_RELEASES_URI,
20
+ GITHUB_USER_URI,
21
+ GITHUB_REPOS_URI,
22
+ GITHUB_ISSUES_URI,
23
+ GITHUB_COMMENTS_URI,
24
+ GITHUB_GIT_TREES_URI,
25
+ GITHUB_GIT_BLOBS_URI,
26
+ GITHUB_GIT_COMMITS_URI,
27
+ GITHUB_ISSUES_COMMENTS_URI,
28
+ GITHUB_LOGIN_OAUTH_AUTHORIZE_URI,
29
+ GITHUB_GIT_REFS_HEADS_MASTER_URI,
30
+ GITHUB_LOGIN_OAUTH_ACCESS_TOKEN_URI
31
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ const { encodings } = require("necessary");
4
+
5
+ const { repoFromRepository, ownerFromRepository } = require("../utilities/repository"),
6
+ { getRequest, postRequest, patchRequest, deleteRequest } = require("../utilities/request"),
7
+ { GITHUB_REPOS_URI, GITHUB_ISSUES_URI, GITHUB_COMMENTS_URI, GITHUB_ISSUES_COMMENTS_URI } = require("../uris");
8
+
9
+ const { UTF_8_ENCODING } = encodings;
10
+
11
+ function commentsGetRequest(repository, issueNumber, userAgent, clientId, clientSecret, callback) {
12
+ const owner = ownerFromRepository(repository),
13
+ repo = repoFromRepository(repository),
14
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}/${issueNumber}${GITHUB_COMMENTS_URI}`,
15
+ query = {};
16
+
17
+ getRequest(uri, query, userAgent, clientId, clientSecret, callback);
18
+ }
19
+
20
+ function editCommentPatchRequest(repository, description, commentIdentifier, userAgent, gitHubAccessToken, callback) {
21
+ const owner = ownerFromRepository(repository),
22
+ repo = repoFromRepository(repository),
23
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_COMMENTS_URI}/${commentIdentifier}`,
24
+ encoding = UTF_8_ENCODING,
25
+ query = {};
26
+
27
+ let body = description; ///
28
+
29
+ body = JSON.stringify({ ///
30
+ body,
31
+ encoding
32
+ });
33
+
34
+ patchRequest(uri, query, body, userAgent, gitHubAccessToken, callback);
35
+ }
36
+
37
+ function createCommentPostRequest(repository, description, issueNumber, userAgent, gitHubAccessToken, callback) {
38
+ const owner = ownerFromRepository(repository),
39
+ repo = repoFromRepository(repository),
40
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}/${issueNumber}${GITHUB_COMMENTS_URI}`,
41
+ encoding = UTF_8_ENCODING,
42
+ query = {};
43
+
44
+ let body = description; ///
45
+
46
+ body = JSON.stringify({ ///
47
+ body,
48
+ encoding
49
+ });
50
+
51
+ postRequest(uri, query, body, userAgent, gitHubAccessToken, callback);
52
+ }
53
+
54
+ function removeCommentDeleteRequest(repository, commentIdentifier, userAgent, gitHubAccessToken, callback) {
55
+ const owner = ownerFromRepository(repository),
56
+ repo = repoFromRepository(repository),
57
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_COMMENTS_URI}/${commentIdentifier}`,
58
+ query = {};
59
+
60
+ deleteRequest(uri, query, userAgent, gitHubAccessToken, callback);
61
+ }
62
+
63
+ module.exports = {
64
+ commentsGetRequest,
65
+ editCommentPatchRequest,
66
+ createCommentPostRequest,
67
+ removeCommentDeleteRequest
68
+ };
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ const { encodings } = require("necessary");
4
+
5
+ const { BLOB_MODE, BLOB_TYPE } = require("../constants"),
6
+ { getRequest, postRequest } = require("../utilities/request"),
7
+ { repoFromRepository, ownerFromRepository } = require("../utilities/repository"),
8
+ { GITHUB_REPOS_URI, GITHUB_GIT_TREES_URI, GITHUB_GIT_BLOBS_URI, GITHUB_GIT_COMMITS_URI, GITHUB_GIT_REFS_HEADS_MASTER_URI } = require("../uris");
9
+
10
+ const { UTF_8_ENCODING } = encodings;
11
+
12
+ function commitSHAPostRequest(repository, commitMessage, commitTreeSHA, latestCommitSHA, userAgent, gitHubAccessToken, callback) {
13
+ const owner = ownerFromRepository(repository),
14
+ repo = repoFromRepository(repository),
15
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_GIT_COMMITS_URI}`,
16
+ tree = commitTreeSHA, ///
17
+ parent = latestCommitSHA, ///
18
+ parents = [
19
+ parent
20
+ ],
21
+ message = commitMessage, ///
22
+ query = {},
23
+ body = JSON.stringify({
24
+ tree,
25
+ parents,
26
+ message
27
+ });
28
+
29
+ postRequest(uri, query, body, userAgent, gitHubAccessToken, callback);
30
+ }
31
+
32
+ function baseTreeSHAGetRequest(repository, latestCommitSHA, userAgent, clientId, clientSecret, callback) {
33
+ const owner = ownerFromRepository(repository),
34
+ repo = repoFromRepository(repository),
35
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_GIT_COMMITS_URI}/${latestCommitSHA}`,
36
+ query = {};
37
+
38
+ getRequest(uri, query, userAgent, clientId, clientSecret, callback);
39
+ }
40
+
41
+ function updatedHeadPostRequest(repository, commitSHA, userAgent, gitHubAccessToken, callback) {
42
+ const owner = ownerFromRepository(repository),
43
+ repo = repoFromRepository(repository),
44
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_GIT_REFS_HEADS_MASTER_URI}`,
45
+ sha = commitSHA, ///
46
+ query = {},
47
+ body = JSON.stringify({
48
+ sha
49
+ });
50
+
51
+ postRequest(uri, query, body, userAgent, gitHubAccessToken, callback);
52
+ }
53
+
54
+ function commitTreeSHAPostRequest(repository, baseTreeSHA, fileSHAs, filePaths, userAgent, gitHubAccessToken, callback) {
55
+ const owner = ownerFromRepository(repository),
56
+ repo = repoFromRepository(repository),
57
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_GIT_TREES_URI}`,
58
+ base_tree = baseTreeSHA, ///
59
+ tree = [],
60
+ mode = BLOB_MODE, ///
61
+ type = BLOB_TYPE; ///
62
+
63
+ fileSHAs.forEach((fileSHA, index) => {
64
+ const filePath = filePaths[index],
65
+ sha = fileSHA, ///
66
+ path = filePath; ///
67
+
68
+ tree.push({
69
+ sha,
70
+ mode,
71
+ type,
72
+ path
73
+ });
74
+ });
75
+
76
+ const query = {},
77
+ body = JSON.stringify({
78
+ base_tree,
79
+ tree
80
+ });
81
+
82
+ postRequest(uri, query, body, userAgent, gitHubAccessToken, callback);
83
+ }
84
+
85
+ function latestCommitSHAGetRequest(repository, userAgent, clientId, clientSecret, callback) {
86
+ const owner = ownerFromRepository(repository),
87
+ repo = repoFromRepository(repository),
88
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_GIT_REFS_HEADS_MASTER_URI}`,
89
+ query = {};
90
+
91
+ getRequest(uri, query, userAgent, clientId, clientSecret, callback);
92
+ }
93
+
94
+ function contentBlobSHAPostRequest(repository, content, userAgent, gitHubAccessToken, callback) {
95
+ const owner = ownerFromRepository(repository),
96
+ repo = repoFromRepository(repository),
97
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_GIT_BLOBS_URI}`,
98
+ encoding = UTF_8_ENCODING, ///
99
+ query = {},
100
+ body = JSON.stringify({
101
+ content,
102
+ encoding
103
+ })
104
+
105
+ postRequest(uri, query, body, userAgent, gitHubAccessToken, callback);
106
+ }
107
+
108
+ module.exports = {
109
+ commitSHAPostRequest,
110
+ baseTreeSHAGetRequest,
111
+ updatedHeadPostRequest,
112
+ commitTreeSHAPostRequest,
113
+ contentBlobSHAPostRequest,
114
+ latestCommitSHAGetRequest
115
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ const { headers, encodings } = require("necessary");
4
+
5
+ const { APPLICATION_VND_GITHUB_VS_JSON } = require("../constants");
6
+
7
+ const { BASE64_ENCODING } = encodings,
8
+ { ACCEPT_HEADER, USER_AGENT_HEADER, CONTENT_TYPE_HEADER, AUTHORIZATION_HEADER } = headers;
9
+
10
+ function headersFromUserAgentAndGitHubAccessToken(userAgent, gitHubAccessToken) {
11
+ const tokenAuthorization = `Token ${gitHubAccessToken}`,
12
+ accept = APPLICATION_VND_GITHUB_VS_JSON, ///
13
+ contentType = APPLICATION_VND_GITHUB_VS_JSON, ///
14
+ authorization = tokenAuthorization, ///
15
+ headers = {
16
+ [ ACCEPT_HEADER ]: accept,
17
+ [ USER_AGENT_HEADER ]: userAgent,
18
+ [ CONTENT_TYPE_HEADER ]: contentType,
19
+ [ AUTHORIZATION_HEADER ]: authorization
20
+ };
21
+
22
+ return headers;
23
+ }
24
+
25
+ function headersFromUserAgentClientIdAndClientSecret(userAgent, clientId, clientSecret) {
26
+ const digest = `${clientId}:${clientSecret}`,
27
+ encodedDigest = Buffer.from(digest).toString(BASE64_ENCODING),
28
+ basicAuthorization = `Basic ${encodedDigest}`,
29
+ accept = APPLICATION_VND_GITHUB_VS_JSON, ///
30
+ authorization = basicAuthorization, ///
31
+ headers = {
32
+ [ ACCEPT_HEADER ]: accept,
33
+ [ USER_AGENT_HEADER ]: userAgent,
34
+ [ AUTHORIZATION_HEADER ]: authorization
35
+ };
36
+
37
+ return headers;
38
+ }
39
+
40
+ module.exports = {
41
+ headersFromUserAgentAndGitHubAccessToken,
42
+ headersFromUserAgentClientIdAndClientSecret
43
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ const { encodings } = require("necessary");
4
+
5
+ const { GITHUB_REPOS_URI, GITHUB_ISSUES_URI } = require("../uris"),
6
+ { getRequest, postRequest, patchRequest } = require("../utilities/request"),
7
+ { repoFromRepository, ownerFromRepository } = require("../utilities/repository");
8
+
9
+ const { UTF_8_ENCODING } = encodings;
10
+
11
+ function issueGetRequest(repository, issueNumber, userAgent, clientId, clientSecret, callback) {
12
+ const owner = ownerFromRepository(repository),
13
+ repo = repoFromRepository(repository),
14
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}/${issueNumber}?`,
15
+ query = {};
16
+
17
+ getRequest(uri, query, userAgent, clientId, clientSecret, callback);
18
+ }
19
+
20
+ function issuesGetRequest(repository, state, userAgent, clientId, clientSecret, callback) {
21
+ const owner = ownerFromRepository(repository),
22
+ repo = repoFromRepository(repository),
23
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}`,
24
+ query = {
25
+ state
26
+ };
27
+
28
+ getRequest(uri, query, userAgent, clientId, clientSecret, callback);
29
+ }
30
+
31
+ function editIssuePatchRequest(repository, title, description, issueNumber, gitHubAccessToken, callback) {
32
+ const owner = ownerFromRepository(repository),
33
+ repo = repoFromRepository(repository),
34
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}/${issueNumber}`,
35
+ encoding = UTF_8_ENCODING,
36
+ query = {};
37
+
38
+ let body = description; ///
39
+
40
+ body = JSON.stringify({ ///
41
+ body,
42
+ title,
43
+ encoding
44
+ });
45
+
46
+ patchRequest(uri, query, body, gitHubAccessToken, callback);
47
+ }
48
+
49
+ function alterIssuePatchRequest(repository, state, issueNumber, gitHubAccessToken, callback) {
50
+ const owner = ownerFromRepository(repository),
51
+ repo = repoFromRepository(repository),
52
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}/${issueNumber}`,
53
+ encoding = UTF_8_ENCODING,
54
+ query = {},
55
+ body = JSON.stringify({ ///
56
+ state,
57
+ encoding
58
+ });
59
+
60
+ patchRequest(uri, query, body, gitHubAccessToken, callback);
61
+ }
62
+
63
+ function createIssuePostRequest(repository, title, description, gitHubAccessToken, callback) {
64
+ const owner = ownerFromRepository(repository),
65
+ repo = repoFromRepository(repository),
66
+ uri = `${GITHUB_REPOS_URI}/${owner}/${repo}${GITHUB_ISSUES_URI}`,
67
+ encoding = UTF_8_ENCODING,
68
+ query = {};
69
+
70
+ let body = description; ///
71
+
72
+ body = JSON.stringify({ ///
73
+ body,
74
+ title,
75
+ encoding
76
+ });
77
+
78
+ postRequest(uri, query, body, gitHubAccessToken, callback);
79
+ }
80
+
81
+ module.exports = {
82
+ issueGetRequest,
83
+ issuesGetRequest,
84
+ editIssuePatchRequest,
85
+ alterIssuePatchRequest,
86
+ createIssuePostRequest
87
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ const { arrayUtilities } = require("necessary");
4
+
5
+ const { second } = arrayUtilities;
6
+
7
+ const repoRegularExpression = /([^\/]+)$/,
8
+ ownerRegularExpression = /([^\/]+)\/[^\/]+$/;
9
+
10
+ function isRepositoryValid(repository) {
11
+ const repoPresent = repoRegularExpression.test(repository),
12
+ ownerPresent = ownerRegularExpression.test(repository),
13
+ repositoryValid = (repoPresent && ownerPresent);
14
+
15
+ return repositoryValid;
16
+ }
17
+
18
+ function repoFromRepository(repository) {
19
+ const matches = repository.match(repoRegularExpression),
20
+ secondMatch = second(matches),
21
+ repo = secondMatch; ///
22
+
23
+ return repo;
24
+ }
25
+
26
+ function ownerFromRepository(repository) {
27
+ const matches = repository.match(ownerRegularExpression),
28
+ secondMatch = second(matches),
29
+ owner = secondMatch; ///
30
+
31
+ return owner;
32
+ }
33
+
34
+ module.exports = {
35
+ isRepositoryValid,
36
+ repoFromRepository,
37
+ ownerFromRepository
38
+ };
39
+
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ const { Readable } = require("stream"),
4
+ { methods, requestUtilities } = require("necessary");
5
+
6
+ const { END, DATA, EMPTY_STRING, GITHUB_API_HOST } = require("../constants"),
7
+ { headersFromUserAgentAndGitHubAccessToken, headersFromUserAgentClientIdAndClientSecret } = require("../utilities/headers");
8
+
9
+ const { createRequest } = requestUtilities,
10
+ { GET_METHOD, POST_METHOD, DELETE_METHOD, PATCH_METHOD } = methods;
11
+
12
+ function getRequest(uri, query, userAgent, clientId, clientSecret, callback) {
13
+ const host = GITHUB_API_HOST,
14
+ method = GET_METHOD,
15
+ headers = headersFromUserAgentClientIdAndClientSecret(userAgent, clientId, clientSecret),
16
+ request = createRequest(host, uri, query, method, headers, (error, response) => {
17
+ contentFromResponse(response, (content) => {
18
+ const jsonString = content, ///
19
+ json = JSON.parse(jsonString);
20
+
21
+ callback(error, json);
22
+ });
23
+ });
24
+
25
+ request.end();
26
+ }
27
+
28
+ function postRequest(uri, query, content, userAgent, gitHubAccessToken, callback) {
29
+ const host = GITHUB_API_HOST,
30
+ method = POST_METHOD,
31
+ headers = headersFromUserAgentAndGitHubAccessToken(userAgent, gitHubAccessToken),
32
+ postRequest = createRequest(host, uri, query, method, headers, (error, response) => {
33
+ contentFromResponse(response, (content) => {
34
+ const jsonString = content, ///
35
+ json = JSON.parse(jsonString);
36
+
37
+ callback(error, json);
38
+ });
39
+ }),
40
+ readable = Readable.from(content);
41
+
42
+ readable.pipe(postRequest);
43
+ }
44
+
45
+ function patchRequest(uri, query, content, userAgent, gitHubAccessToken, callback) {
46
+ const host = GITHUB_API_HOST,
47
+ method = PATCH_METHOD,
48
+ headers = headersFromUserAgentAndGitHubAccessToken(userAgent, gitHubAccessToken),
49
+ postRequest = createRequest(host, uri, query, method, headers, (error, response) => {
50
+ contentFromResponse(response, (content) => {
51
+ const jsonString = content, ///
52
+ json = JSON.parse(jsonString);
53
+
54
+ callback(error, json);
55
+ });
56
+ }),
57
+ readable = Readable.from(content);
58
+
59
+ readable.pipe(postRequest);
60
+ }
61
+
62
+ function deleteRequest(uri, query, userAgent, gitHubAccessToken, callback) {
63
+ const host = GITHUB_API_HOST,
64
+ method = DELETE_METHOD,
65
+ headers = headersFromUserAgentAndGitHubAccessToken(userAgent, gitHubAccessToken),
66
+ deleteRequest = createRequest(host, uri, query, method, headers, (error, response) => {
67
+ contentFromResponse(response, (content) => {
68
+ const string = content; ///
69
+
70
+ callback(error, string);
71
+ });
72
+ });
73
+
74
+ deleteRequest.end();
75
+ }
76
+
77
+ module.exports = {
78
+ getRequest,
79
+ postRequest,
80
+ patchRequest,
81
+ deleteRequest
82
+ };
83
+
84
+ function contentFromResponse(response, callback) {
85
+ let content = EMPTY_STRING;
86
+
87
+ response.on(DATA, (data) => {
88
+ content += data;
89
+ });
90
+
91
+ response.on(END, () => {
92
+ callback(content);
93
+ });
94
+ }
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const issueUtilities = require("./bin/utilities/issue"),
4
+ commitUtilities = require("./bin/utilities/commit"),
5
+ commentUtilities = require("./bin/utilities/comment");
6
+
7
+ module.exports = {
8
+ issueUtilities,
9
+ commitUtilities,
10
+ commentUtilities
11
+ };