@airscript/ghitgud 1.0.2 → 2.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/README.md +104 -18
- package/VERSION +1 -1
- package/dist/index.js +793 -0
- package/dist/templates/base.json +12 -0
- package/dist/templates/conventional.json +52 -0
- package/dist/templates/github.json +47 -0
- package/package.json +59 -36
- package/templates/base.json +1 -1
- package/templates/conventional.json +51 -52
- package/templates/github.json +1 -1
- package/.env.base +0 -2
- package/.github/CODEOWNERS +0 -1
- package/.github/FUNDING.yml +0 -2
- package/.github/ISSUE_TEMPLATE/build.md +0 -9
- package/.github/ISSUE_TEMPLATE/chore.md +0 -9
- package/.github/ISSUE_TEMPLATE/ci.md +0 -9
- package/.github/ISSUE_TEMPLATE/documentation.md +0 -9
- package/.github/ISSUE_TEMPLATE/feature.md +0 -9
- package/.github/ISSUE_TEMPLATE/fix.md +0 -9
- package/.github/ISSUE_TEMPLATE/performance.md +0 -9
- package/.github/ISSUE_TEMPLATE/refactor.md +0 -9
- package/.github/ISSUE_TEMPLATE/style.md +0 -9
- package/.github/ISSUE_TEMPLATE/test.md +0 -9
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -28
- package/.github/workflows/tests.yml +0 -36
- package/CHANGELOG.md +0 -23
- package/CITATION.cff +0 -13
- package/CODE_OF_CONDUCT.md +0 -121
- package/CONTRIBUTING.md +0 -2
- package/SECURITY.md +0 -9
- package/app/api.ts +0 -136
- package/app/ascii.ts +0 -18
- package/app/commands.ts +0 -117
- package/app/config.ts +0 -9
- package/app/functions.ts +0 -43
- package/app/ghitgud.ts +0 -18
- package/app/library.ts +0 -157
- package/app/types.ts +0 -8
- package/dist/app/api.js +0 -127
- package/dist/app/ascii.js +0 -20
- package/dist/app/commands.js +0 -89
- package/dist/app/config.js +0 -12
- package/dist/app/functions.js +0 -37
- package/dist/app/ghitgud.js +0 -19
- package/dist/app/library.js +0 -122
- package/dist/app/types.js +0 -2
- package/dist/tests/library.test.js +0 -81
- package/scripts/clean.sh +0 -2
- package/tests/library.test.ts +0 -77
- package/tsconfig.json +0 -113
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
We as members, contributors, and leaders pledge to make participation in our
|
|
5
|
-
community a harassment-free experience for everyone, regardless of age, body
|
|
6
|
-
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
7
|
-
identity and expression, level of experience, education, socio-economic status,
|
|
8
|
-
nationality, personal appearance, race, caste, color, religion, or sexual identity
|
|
9
|
-
and orientation.
|
|
10
|
-
|
|
11
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
12
|
-
diverse, inclusive, and healthy community.
|
|
13
|
-
|
|
14
|
-
## Our Standards
|
|
15
|
-
Examples of behavior that contributes to a positive environment for our
|
|
16
|
-
community include:
|
|
17
|
-
|
|
18
|
-
* Demonstrating empathy and kindness toward other people
|
|
19
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
20
|
-
* Giving and gracefully accepting constructive feedback
|
|
21
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
22
|
-
and learning from the experience
|
|
23
|
-
* Focusing on what is best not just for us as individuals, but for the
|
|
24
|
-
overall community
|
|
25
|
-
|
|
26
|
-
Examples of unacceptable behavior include:
|
|
27
|
-
|
|
28
|
-
* The use of sexualized language or imagery, and sexual attention or
|
|
29
|
-
advances of any kind
|
|
30
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
31
|
-
* Public or private harassment
|
|
32
|
-
* Publishing others' private information, such as a physical or email
|
|
33
|
-
address, without their explicit permission
|
|
34
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
35
|
-
professional setting
|
|
36
|
-
|
|
37
|
-
## Enforcement Responsibilities
|
|
38
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
|
39
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
|
40
|
-
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
41
|
-
or harmful.
|
|
42
|
-
|
|
43
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
|
44
|
-
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
45
|
-
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
46
|
-
decisions when appropriate.
|
|
47
|
-
|
|
48
|
-
## Scope
|
|
49
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
|
50
|
-
an individual is officially representing the community in public spaces.
|
|
51
|
-
Examples of representing our community include using an official e-mail address,
|
|
52
|
-
posting via an official social media account, or acting as an appointed
|
|
53
|
-
representative at an online or offline event.
|
|
54
|
-
|
|
55
|
-
## Enforcement
|
|
56
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
57
|
-
reported to the community leaders responsible for enforcement at
|
|
58
|
-
<francesco@airscript.it>.
|
|
59
|
-
All complaints will be reviewed and investigated promptly and fairly.
|
|
60
|
-
|
|
61
|
-
All community leaders are obligated to respect the privacy and security of the
|
|
62
|
-
reporter of any incident.
|
|
63
|
-
|
|
64
|
-
## Enforcement Guidelines
|
|
65
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
|
66
|
-
the consequences for any action they deem in violation of this Code of Conduct:
|
|
67
|
-
|
|
68
|
-
### 1. Correction
|
|
69
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
70
|
-
unprofessional or unwelcome in the community.
|
|
71
|
-
|
|
72
|
-
**Consequence**: A private, written warning from community leaders, providing
|
|
73
|
-
clarity around the nature of the violation and an explanation of why the
|
|
74
|
-
behavior was inappropriate. A public apology may be requested.
|
|
75
|
-
|
|
76
|
-
### 2. Warning
|
|
77
|
-
**Community Impact**: A violation through a single incident or series
|
|
78
|
-
of actions.
|
|
79
|
-
|
|
80
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
|
81
|
-
interaction with the people involved, including unsolicited interaction with
|
|
82
|
-
those enforcing the Code of Conduct, for a specified period of time. This
|
|
83
|
-
includes avoiding interactions in community spaces as well as external channels
|
|
84
|
-
like social media. Violating these terms may lead to a temporary or
|
|
85
|
-
permanent ban.
|
|
86
|
-
|
|
87
|
-
### 3. Temporary Ban
|
|
88
|
-
**Community Impact**: A serious violation of community standards, including
|
|
89
|
-
sustained inappropriate behavior.
|
|
90
|
-
|
|
91
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
|
92
|
-
communication with the community for a specified period of time. No public or
|
|
93
|
-
private interaction with the people involved, including unsolicited interaction
|
|
94
|
-
with those enforcing the Code of Conduct, is allowed during this period.
|
|
95
|
-
Violating these terms may lead to a permanent ban.
|
|
96
|
-
|
|
97
|
-
### 4. Permanent Ban
|
|
98
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
|
99
|
-
standards, including sustained inappropriate behavior, harassment of an
|
|
100
|
-
individual, or aggression toward or disparagement of classes of individuals.
|
|
101
|
-
|
|
102
|
-
**Consequence**: A permanent ban from any sort of public interaction within
|
|
103
|
-
the community.
|
|
104
|
-
|
|
105
|
-
## Attribution
|
|
106
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
107
|
-
version 2.0, available at
|
|
108
|
-
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
|
109
|
-
|
|
110
|
-
Community Impact Guidelines were inspired by
|
|
111
|
-
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
112
|
-
|
|
113
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
114
|
-
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
|
115
|
-
at [https://www.contributor-covenant.org/translations][translations].
|
|
116
|
-
|
|
117
|
-
[homepage]: https://www.contributor-covenant.org
|
|
118
|
-
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
|
119
|
-
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
120
|
-
[FAQ]: https://www.contributor-covenant.org/faq
|
|
121
|
-
[translations]: https://www.contributor-covenant.org/translations
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository, ensuring you follow the [Code of Conduct](https://github.com/airscripts/ghitgud/blob/main/CODE_OF_CONDUCT.md).
|
package/SECURITY.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Supported Versions
|
|
4
|
-
| Version | Supported |
|
|
5
|
-
| ------- | ------------------ |
|
|
6
|
-
| 1.0.x | :white_check_mark: |
|
|
7
|
-
|
|
8
|
-
## Reporting Vulnerability
|
|
9
|
-
To report a vulnerability, open an [issue](https://github.com/airscripts/ghitgud/issues/new/choose).
|
package/app/api.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import config from "./config";
|
|
2
|
-
import { Label } from "./types";
|
|
3
|
-
import functions from "./functions";
|
|
4
|
-
import "dotenv/config";
|
|
5
|
-
|
|
6
|
-
const VERSION = "2022-11-28";
|
|
7
|
-
const BASE_URL = "https://api.github.com";
|
|
8
|
-
const ACCEPT = "application/vnd.github+json";
|
|
9
|
-
const REPO = `${config.repo}`;
|
|
10
|
-
const AUTHORIZATION = `Bearer ${config.token}`;
|
|
11
|
-
|
|
12
|
-
const ERROR_UNAUTHORIZED = "Unauthorized.";
|
|
13
|
-
const ERROR_UNPROCESSABLE = "Content is unprocessable.";
|
|
14
|
-
const ERROR_NO_REPO = "You must set the GHITGUD_GITHUB_REPO environment variable.";
|
|
15
|
-
const ERROR_NO_TOKEN = "You must set the GHITGUD_GITHUB_TOKEN environment variable.";
|
|
16
|
-
|
|
17
|
-
const labels = {
|
|
18
|
-
fetch: async () => {
|
|
19
|
-
if (!functions.environment.hasRepo()) throw new Error(ERROR_NO_REPO);
|
|
20
|
-
if (!functions.environment.hasToken()) throw new Error(ERROR_NO_TOKEN);
|
|
21
|
-
|
|
22
|
-
const response = await fetch(`${BASE_URL}/repos/${REPO}/labels`, {
|
|
23
|
-
headers: {
|
|
24
|
-
Accept: ACCEPT,
|
|
25
|
-
Authorization: AUTHORIZATION,
|
|
26
|
-
"X-GitHub-Api-Version": VERSION,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (functions.http.isNotAuthorized(response.status))
|
|
31
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
32
|
-
|
|
33
|
-
return response;
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
get: async (name: string) => {
|
|
37
|
-
if (!functions.environment.hasRepo()) throw new Error(ERROR_NO_REPO);
|
|
38
|
-
if (!functions.environment.hasToken()) throw new Error(ERROR_NO_TOKEN);
|
|
39
|
-
|
|
40
|
-
const response = await fetch(`${BASE_URL}/repos/${REPO}/labels/${name}`, {
|
|
41
|
-
method: "GET",
|
|
42
|
-
headers: {
|
|
43
|
-
Accept: ACCEPT,
|
|
44
|
-
Authorization: AUTHORIZATION,
|
|
45
|
-
"X-GitHub-Api-Version": VERSION,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (functions.http.isNotAuthorized(response.status))
|
|
50
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
51
|
-
|
|
52
|
-
return response;
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
create: async (label: Label) => {
|
|
56
|
-
if (!functions.environment.hasRepo()) throw new Error(ERROR_NO_REPO);
|
|
57
|
-
if (!functions.environment.hasToken()) throw new Error(ERROR_NO_TOKEN);
|
|
58
|
-
|
|
59
|
-
const response = await fetch(`${BASE_URL}/repos/${REPO}/labels`, {
|
|
60
|
-
method: "POST",
|
|
61
|
-
|
|
62
|
-
body: JSON.stringify({
|
|
63
|
-
name: label.name,
|
|
64
|
-
color: label.color,
|
|
65
|
-
description: label.description,
|
|
66
|
-
}),
|
|
67
|
-
|
|
68
|
-
headers: {
|
|
69
|
-
Accept: ACCEPT,
|
|
70
|
-
Authorization: AUTHORIZATION,
|
|
71
|
-
"X-GitHub-Api-Version": VERSION,
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
if (functions.http.isUnprocessable(response.status))
|
|
76
|
-
throw new Error(ERROR_UNPROCESSABLE);
|
|
77
|
-
|
|
78
|
-
if (functions.http.isNotAuthorized(response.status))
|
|
79
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
80
|
-
|
|
81
|
-
return response;
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
patch: async (label: Label) => {
|
|
85
|
-
if (!functions.environment.hasRepo()) throw new Error(ERROR_NO_REPO);
|
|
86
|
-
if (!functions.environment.hasToken()) throw new Error(ERROR_NO_TOKEN);
|
|
87
|
-
|
|
88
|
-
const response = await fetch(
|
|
89
|
-
`${BASE_URL}/repos/${REPO}/labels/${label.name}`,
|
|
90
|
-
{
|
|
91
|
-
method: "PATCH",
|
|
92
|
-
|
|
93
|
-
body: JSON.stringify({
|
|
94
|
-
color: label.color,
|
|
95
|
-
description: label.description,
|
|
96
|
-
new_name: label.newName || label.name,
|
|
97
|
-
}),
|
|
98
|
-
|
|
99
|
-
headers: {
|
|
100
|
-
Accept: ACCEPT,
|
|
101
|
-
Authorization: AUTHORIZATION,
|
|
102
|
-
"X-GitHub-Api-Version": VERSION,
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
if (functions.http.isNotAuthorized(response.status))
|
|
108
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
109
|
-
|
|
110
|
-
return response;
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
delete: async (name: string) => {
|
|
114
|
-
if (!functions.environment.hasRepo()) throw new Error(ERROR_NO_REPO);
|
|
115
|
-
if (!functions.environment.hasToken()) throw new Error(ERROR_NO_TOKEN);
|
|
116
|
-
|
|
117
|
-
const response = await fetch(`${BASE_URL}/repos/${REPO}/labels/${name}`, {
|
|
118
|
-
method: "DELETE",
|
|
119
|
-
|
|
120
|
-
headers: {
|
|
121
|
-
Accept: ACCEPT,
|
|
122
|
-
Authorization: AUTHORIZATION,
|
|
123
|
-
"X-GitHub-Api-Version": VERSION,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
if (functions.http.isNotAuthorized(response.status))
|
|
128
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
129
|
-
|
|
130
|
-
return response;
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export default {
|
|
135
|
-
labels,
|
|
136
|
-
};
|
package/app/ascii.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import figlet from "figlet";
|
|
2
|
-
|
|
3
|
-
const WIDTH = 80;
|
|
4
|
-
const TITLE = "Ghitgud";
|
|
5
|
-
const FONT = "Standard";
|
|
6
|
-
const WHITESPACE_BREAK = true;
|
|
7
|
-
const VERTICAL_LAYOUT = "default";
|
|
8
|
-
const HORIZONTAL_LAYOUT = "default";
|
|
9
|
-
|
|
10
|
-
const ascii = figlet.textSync(TITLE, {
|
|
11
|
-
font: FONT,
|
|
12
|
-
width: WIDTH,
|
|
13
|
-
verticalLayout: VERTICAL_LAYOUT,
|
|
14
|
-
whitespaceBreak: WHITESPACE_BREAK,
|
|
15
|
-
horizontalLayout: HORIZONTAL_LAYOUT,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export default ascii;
|
package/app/commands.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { program, Command } from "commander";
|
|
2
|
-
import library from "./library";
|
|
3
|
-
|
|
4
|
-
const COMMANDS = {
|
|
5
|
-
ping: {
|
|
6
|
-
name: "ping",
|
|
7
|
-
action: () => void library.ping(),
|
|
8
|
-
description: "Check if the CLI is working.",
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
labels: {
|
|
12
|
-
name: "labels",
|
|
13
|
-
description: "Manage labels for a repository.",
|
|
14
|
-
|
|
15
|
-
commands: {
|
|
16
|
-
list: {
|
|
17
|
-
name: "list",
|
|
18
|
-
description: "List all labels for a repository.",
|
|
19
|
-
action: () => void library.labels.list(),
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
pull: {
|
|
23
|
-
name: "pull",
|
|
24
|
-
description: "Pull all related labels for a repository.",
|
|
25
|
-
action: () => void library.labels.pull(),
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
push: {
|
|
29
|
-
name: "push",
|
|
30
|
-
description: "Push all related labels for a repository.",
|
|
31
|
-
action: () => void library.labels.push(),
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
prune: {
|
|
35
|
-
name: "prune",
|
|
36
|
-
description: "Prune all related labels for a repository.",
|
|
37
|
-
action: () => void library.labels.prune(),
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
config: {
|
|
43
|
-
name: "config",
|
|
44
|
-
description: "Set CLI configurations.",
|
|
45
|
-
|
|
46
|
-
commands: {
|
|
47
|
-
set: {
|
|
48
|
-
name: "set",
|
|
49
|
-
description: "Set configuration.",
|
|
50
|
-
|
|
51
|
-
action: (key: string, value: string) =>
|
|
52
|
-
void library.config.set(key, value),
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const ping = () => {
|
|
59
|
-
program
|
|
60
|
-
.command(COMMANDS.ping.name)
|
|
61
|
-
.description(COMMANDS.ping.description)
|
|
62
|
-
.action(COMMANDS.ping.action);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const labels = () => {
|
|
66
|
-
const labels = program
|
|
67
|
-
.command(COMMANDS.labels.name)
|
|
68
|
-
.description(COMMANDS.labels.description);
|
|
69
|
-
|
|
70
|
-
labels.addCommand(
|
|
71
|
-
new Command(COMMANDS.labels.commands.list.name)
|
|
72
|
-
.description(COMMANDS.labels.commands.list.description)
|
|
73
|
-
.action(COMMANDS.labels.commands.list.action)
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
labels.addCommand(
|
|
77
|
-
new Command(COMMANDS.labels.commands.pull.name)
|
|
78
|
-
.description(COMMANDS.labels.commands.pull.description)
|
|
79
|
-
.action(COMMANDS.labels.commands.pull.action)
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
labels.addCommand(
|
|
83
|
-
new Command(COMMANDS.labels.commands.push.name)
|
|
84
|
-
.description(COMMANDS.labels.commands.push.description)
|
|
85
|
-
.action(COMMANDS.labels.commands.push.action)
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
labels.addCommand(
|
|
89
|
-
new Command(COMMANDS.labels.commands.prune.name)
|
|
90
|
-
.description(COMMANDS.labels.commands.prune.description)
|
|
91
|
-
.action(COMMANDS.labels.commands.prune.action)
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const config = () => {
|
|
96
|
-
const config = program
|
|
97
|
-
.command(COMMANDS.config.name)
|
|
98
|
-
.description(COMMANDS.config.description);
|
|
99
|
-
|
|
100
|
-
config.addCommand(
|
|
101
|
-
new Command(COMMANDS.config.commands.set.name)
|
|
102
|
-
.description(COMMANDS.config.commands.set.description)
|
|
103
|
-
.arguments("<key> <value>")
|
|
104
|
-
|
|
105
|
-
.action((key: string, value: string) =>
|
|
106
|
-
COMMANDS.config.commands.set.action(key, value)
|
|
107
|
-
)
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const init = () => {
|
|
112
|
-
ping();
|
|
113
|
-
labels();
|
|
114
|
-
config();
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export default init;
|
package/app/config.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import functions from "./functions";
|
|
2
|
-
import "dotenv/config";
|
|
3
|
-
|
|
4
|
-
const config = {
|
|
5
|
-
repo: process.env.GHITGUD_GITHUB_REPO || functions?.config.read("repo"),
|
|
6
|
-
token: process.env.GHITGUD_GITHUB_TOKEN || functions?.config.read("token"),
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default config;
|
package/app/functions.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import os from "os";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
import conf from "./config";
|
|
6
|
-
import "dotenv/config";
|
|
7
|
-
|
|
8
|
-
const STATUS_OK = 200;
|
|
9
|
-
const STATUS_UNAUTHORIZED = 401;
|
|
10
|
-
const STATUS_NOT_FOUND = 404;
|
|
11
|
-
const STATUS_UNPROCESSABLE = 422;
|
|
12
|
-
|
|
13
|
-
const ENCODING = "utf8";
|
|
14
|
-
const CREDENTIALS_FILE = "credentials.json";
|
|
15
|
-
const GHITGUD_FOLDER = path.join(os.homedir(), ".config", "ghitgud");
|
|
16
|
-
|
|
17
|
-
const http = {
|
|
18
|
-
isOk: (status: number) => status === STATUS_OK,
|
|
19
|
-
isNotFound: (status: number) => status === STATUS_NOT_FOUND,
|
|
20
|
-
isNotAuthorized: (status: number) => status === STATUS_UNAUTHORIZED,
|
|
21
|
-
isUnprocessable: (status: number) => status === STATUS_UNPROCESSABLE,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const environment = {
|
|
25
|
-
hasRepo: () => (conf.repo ? true : false),
|
|
26
|
-
hasToken: () => (conf.token ? true : false),
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const config = {
|
|
30
|
-
read: (key: string) => {
|
|
31
|
-
if (!fs.existsSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`)) return null;
|
|
32
|
-
|
|
33
|
-
const data = fs.readFileSync(
|
|
34
|
-
`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`,
|
|
35
|
-
ENCODING
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const content = JSON.parse(data);
|
|
39
|
-
return content[key];
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default { http, environment, config };
|
package/app/ghitgud.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import process from "process";
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
|
|
4
|
-
import ascii from "./ascii";
|
|
5
|
-
import commands from "./commands";
|
|
6
|
-
|
|
7
|
-
const NAME = "ghitgud";
|
|
8
|
-
const VERSION = "1.0.2";
|
|
9
|
-
const DESCRIPTION = "A simple CLI to give superpowers to GitHub.";
|
|
10
|
-
|
|
11
|
-
program
|
|
12
|
-
.name(NAME)
|
|
13
|
-
.description(DESCRIPTION)
|
|
14
|
-
.version(VERSION);
|
|
15
|
-
|
|
16
|
-
commands();
|
|
17
|
-
program.addHelpText("before", ascii);
|
|
18
|
-
program.parse(process.argv);
|
package/app/library.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import os from "os";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
import api from "./api";
|
|
6
|
-
import { Label } from "./types";
|
|
7
|
-
import functions from "./functions";
|
|
8
|
-
|
|
9
|
-
const ENCODING = "utf8";
|
|
10
|
-
const PING_RESPONSE = "pong";
|
|
11
|
-
const METADATA_FILE = "labels.json";
|
|
12
|
-
const ERROR_NO_METADATA = "No metadata file found.";
|
|
13
|
-
|
|
14
|
-
const CREDENTIALS_FILE = "credentials.json";
|
|
15
|
-
const ERROR_UNSUPPORTED_KEY = "Trying to set unsupported key.";
|
|
16
|
-
const GHITGUD_FOLDER = path.join(os.homedir(), ".config", "ghitgud");
|
|
17
|
-
|
|
18
|
-
const ping = () => {
|
|
19
|
-
console.info(PING_RESPONSE);
|
|
20
|
-
return { success: true };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const labels = {
|
|
24
|
-
list: async () => {
|
|
25
|
-
const response = await api.labels.fetch();
|
|
26
|
-
const data = await response.json();
|
|
27
|
-
|
|
28
|
-
const labels = data.map((label: Label) => ({
|
|
29
|
-
name: label.name,
|
|
30
|
-
color: label.color,
|
|
31
|
-
description: label.description,
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
const result = { success: true, metadata: labels };
|
|
35
|
-
console.info(result);
|
|
36
|
-
return result;
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
pull: async () => {
|
|
40
|
-
const response = await api.labels.fetch();
|
|
41
|
-
const data = await response.json();
|
|
42
|
-
|
|
43
|
-
const labels = data.map((label: Label) => ({
|
|
44
|
-
name: label.name,
|
|
45
|
-
color: label.color,
|
|
46
|
-
description: label.description,
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
fs.mkdirSync(GHITGUD_FOLDER, { recursive: true });
|
|
51
|
-
} catch (error) {
|
|
52
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
fs.writeFileSync(
|
|
57
|
-
`${GHITGUD_FOLDER}/${METADATA_FILE}`,
|
|
58
|
-
JSON.stringify(labels, null, 2)
|
|
59
|
-
);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const result = { success: true };
|
|
65
|
-
console.info(result);
|
|
66
|
-
return result;
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
push: async () => {
|
|
70
|
-
if (!fs.existsSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`))
|
|
71
|
-
throw new Error(ERROR_NO_METADATA);
|
|
72
|
-
|
|
73
|
-
const data = fs.readFileSync(
|
|
74
|
-
`${GHITGUD_FOLDER}/${METADATA_FILE}`,
|
|
75
|
-
ENCODING
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const labels = JSON.parse(data);
|
|
79
|
-
|
|
80
|
-
await Promise.all(
|
|
81
|
-
labels.map(async (label: Label) => {
|
|
82
|
-
const response = await api.labels.get(label.name);
|
|
83
|
-
if (functions.http.isOk(response.status)) await api.labels.patch(label);
|
|
84
|
-
|
|
85
|
-
if (functions.http.isNotFound(response.status))
|
|
86
|
-
await api.labels.create(label);
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const result = { success: true };
|
|
91
|
-
console.info(result);
|
|
92
|
-
return result;
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
prune: async () => {
|
|
96
|
-
if (!fs.existsSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`))
|
|
97
|
-
throw new Error(ERROR_NO_METADATA);
|
|
98
|
-
|
|
99
|
-
const data = fs.readFileSync(
|
|
100
|
-
`${GHITGUD_FOLDER}/${METADATA_FILE}`,
|
|
101
|
-
ENCODING
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const labels = JSON.parse(data);
|
|
105
|
-
labels.map(async (label: Label) => await api.labels.delete(label.name));
|
|
106
|
-
|
|
107
|
-
const result = { success: true };
|
|
108
|
-
console.info(result);
|
|
109
|
-
return result;
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const config = {
|
|
114
|
-
set: (key: string, value: string) => {
|
|
115
|
-
const knowns = ["token", "repo"];
|
|
116
|
-
|
|
117
|
-
if (!knowns.includes(key)) throw new Error(ERROR_UNSUPPORTED_KEY);
|
|
118
|
-
|
|
119
|
-
if (!fs.existsSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`)) {
|
|
120
|
-
const credentials = { [key]: value };
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
fs.mkdirSync(GHITGUD_FOLDER, { recursive: true });
|
|
124
|
-
} catch (error) {
|
|
125
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
fs.writeFileSync(
|
|
129
|
-
`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`,
|
|
130
|
-
JSON.stringify(credentials, null, 2)
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
return { success: true };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const data = fs.readFileSync(
|
|
137
|
-
`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`,
|
|
138
|
-
ENCODING
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const credentials = JSON.parse(data);
|
|
142
|
-
credentials[key] = value;
|
|
143
|
-
|
|
144
|
-
fs.writeFileSync(
|
|
145
|
-
`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`,
|
|
146
|
-
JSON.stringify(credentials, null, 2)
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
return { success: true };
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export default {
|
|
154
|
-
ping,
|
|
155
|
-
labels,
|
|
156
|
-
config,
|
|
157
|
-
};
|