@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/dist/app/api.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const config_1 = __importDefault(require("./config"));
|
|
16
|
-
const functions_1 = __importDefault(require("./functions"));
|
|
17
|
-
require("dotenv/config");
|
|
18
|
-
const VERSION = "2022-11-28";
|
|
19
|
-
const BASE_URL = "https://api.github.com";
|
|
20
|
-
const ACCEPT = "application/vnd.github+json";
|
|
21
|
-
const REPO = `${config_1.default.repo}`;
|
|
22
|
-
const AUTHORIZATION = `Bearer ${config_1.default.token}`;
|
|
23
|
-
const ERROR_UNAUTHORIZED = "Unauthorized.";
|
|
24
|
-
const ERROR_UNPROCESSABLE = "Content is unprocessable.";
|
|
25
|
-
const ERROR_NO_REPO = "You must set the GHITGUD_GITHUB_REPO environment variable.";
|
|
26
|
-
const ERROR_NO_TOKEN = "You must set the GHITGUD_GITHUB_TOKEN environment variable.";
|
|
27
|
-
const labels = {
|
|
28
|
-
fetch: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
if (!functions_1.default.environment.hasRepo())
|
|
30
|
-
throw new Error(ERROR_NO_REPO);
|
|
31
|
-
if (!functions_1.default.environment.hasToken())
|
|
32
|
-
throw new Error(ERROR_NO_TOKEN);
|
|
33
|
-
const response = yield fetch(`${BASE_URL}/repos/${REPO}/labels`, {
|
|
34
|
-
headers: {
|
|
35
|
-
Accept: ACCEPT,
|
|
36
|
-
Authorization: AUTHORIZATION,
|
|
37
|
-
"X-GitHub-Api-Version": VERSION,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
if (functions_1.default.http.isNotAuthorized(response.status))
|
|
41
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
42
|
-
return response;
|
|
43
|
-
}),
|
|
44
|
-
get: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
if (!functions_1.default.environment.hasRepo())
|
|
46
|
-
throw new Error(ERROR_NO_REPO);
|
|
47
|
-
if (!functions_1.default.environment.hasToken())
|
|
48
|
-
throw new Error(ERROR_NO_TOKEN);
|
|
49
|
-
const response = yield fetch(`${BASE_URL}/repos/${REPO}/labels/${name}`, {
|
|
50
|
-
method: "GET",
|
|
51
|
-
headers: {
|
|
52
|
-
Accept: ACCEPT,
|
|
53
|
-
Authorization: AUTHORIZATION,
|
|
54
|
-
"X-GitHub-Api-Version": VERSION,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
if (functions_1.default.http.isNotAuthorized(response.status))
|
|
58
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
59
|
-
return response;
|
|
60
|
-
}),
|
|
61
|
-
create: (label) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
if (!functions_1.default.environment.hasRepo())
|
|
63
|
-
throw new Error(ERROR_NO_REPO);
|
|
64
|
-
if (!functions_1.default.environment.hasToken())
|
|
65
|
-
throw new Error(ERROR_NO_TOKEN);
|
|
66
|
-
const response = yield fetch(`${BASE_URL}/repos/${REPO}/labels`, {
|
|
67
|
-
method: "POST",
|
|
68
|
-
body: JSON.stringify({
|
|
69
|
-
name: label.name,
|
|
70
|
-
color: label.color,
|
|
71
|
-
description: label.description,
|
|
72
|
-
}),
|
|
73
|
-
headers: {
|
|
74
|
-
Accept: ACCEPT,
|
|
75
|
-
Authorization: AUTHORIZATION,
|
|
76
|
-
"X-GitHub-Api-Version": VERSION,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
if (functions_1.default.http.isUnprocessable(response.status))
|
|
80
|
-
throw new Error(ERROR_UNPROCESSABLE);
|
|
81
|
-
if (functions_1.default.http.isNotAuthorized(response.status))
|
|
82
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
83
|
-
return response;
|
|
84
|
-
}),
|
|
85
|
-
patch: (label) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
-
if (!functions_1.default.environment.hasRepo())
|
|
87
|
-
throw new Error(ERROR_NO_REPO);
|
|
88
|
-
if (!functions_1.default.environment.hasToken())
|
|
89
|
-
throw new Error(ERROR_NO_TOKEN);
|
|
90
|
-
const response = yield fetch(`${BASE_URL}/repos/${REPO}/labels/${label.name}`, {
|
|
91
|
-
method: "PATCH",
|
|
92
|
-
body: JSON.stringify({
|
|
93
|
-
color: label.color,
|
|
94
|
-
description: label.description,
|
|
95
|
-
new_name: label.newName || label.name,
|
|
96
|
-
}),
|
|
97
|
-
headers: {
|
|
98
|
-
Accept: ACCEPT,
|
|
99
|
-
Authorization: AUTHORIZATION,
|
|
100
|
-
"X-GitHub-Api-Version": VERSION,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
if (functions_1.default.http.isNotAuthorized(response.status))
|
|
104
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
105
|
-
return response;
|
|
106
|
-
}),
|
|
107
|
-
delete: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
-
if (!functions_1.default.environment.hasRepo())
|
|
109
|
-
throw new Error(ERROR_NO_REPO);
|
|
110
|
-
if (!functions_1.default.environment.hasToken())
|
|
111
|
-
throw new Error(ERROR_NO_TOKEN);
|
|
112
|
-
const response = yield fetch(`${BASE_URL}/repos/${REPO}/labels/${name}`, {
|
|
113
|
-
method: "DELETE",
|
|
114
|
-
headers: {
|
|
115
|
-
Accept: ACCEPT,
|
|
116
|
-
Authorization: AUTHORIZATION,
|
|
117
|
-
"X-GitHub-Api-Version": VERSION,
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
if (functions_1.default.http.isNotAuthorized(response.status))
|
|
121
|
-
throw new Error(ERROR_UNAUTHORIZED);
|
|
122
|
-
return response;
|
|
123
|
-
}),
|
|
124
|
-
};
|
|
125
|
-
exports.default = {
|
|
126
|
-
labels,
|
|
127
|
-
};
|
package/dist/app/ascii.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const figlet_1 = __importDefault(require("figlet"));
|
|
7
|
-
const WIDTH = 80;
|
|
8
|
-
const TITLE = "Ghitgud";
|
|
9
|
-
const FONT = "Standard";
|
|
10
|
-
const WHITESPACE_BREAK = true;
|
|
11
|
-
const VERTICAL_LAYOUT = "default";
|
|
12
|
-
const HORIZONTAL_LAYOUT = "default";
|
|
13
|
-
const ascii = figlet_1.default.textSync(TITLE, {
|
|
14
|
-
font: FONT,
|
|
15
|
-
width: WIDTH,
|
|
16
|
-
verticalLayout: VERTICAL_LAYOUT,
|
|
17
|
-
whitespaceBreak: WHITESPACE_BREAK,
|
|
18
|
-
horizontalLayout: HORIZONTAL_LAYOUT,
|
|
19
|
-
});
|
|
20
|
-
exports.default = ascii;
|
package/dist/app/commands.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const commander_1 = require("commander");
|
|
7
|
-
const library_1 = __importDefault(require("./library"));
|
|
8
|
-
const COMMANDS = {
|
|
9
|
-
ping: {
|
|
10
|
-
name: "ping",
|
|
11
|
-
action: () => void library_1.default.ping(),
|
|
12
|
-
description: "Check if the CLI is working.",
|
|
13
|
-
},
|
|
14
|
-
labels: {
|
|
15
|
-
name: "labels",
|
|
16
|
-
description: "Manage labels for a repository.",
|
|
17
|
-
commands: {
|
|
18
|
-
list: {
|
|
19
|
-
name: "list",
|
|
20
|
-
description: "List all labels for a repository.",
|
|
21
|
-
action: () => void library_1.default.labels.list(),
|
|
22
|
-
},
|
|
23
|
-
pull: {
|
|
24
|
-
name: "pull",
|
|
25
|
-
description: "Pull all related labels for a repository.",
|
|
26
|
-
action: () => void library_1.default.labels.pull(),
|
|
27
|
-
},
|
|
28
|
-
push: {
|
|
29
|
-
name: "push",
|
|
30
|
-
description: "Push all related labels for a repository.",
|
|
31
|
-
action: () => void library_1.default.labels.push(),
|
|
32
|
-
},
|
|
33
|
-
prune: {
|
|
34
|
-
name: "prune",
|
|
35
|
-
description: "Prune all related labels for a repository.",
|
|
36
|
-
action: () => void library_1.default.labels.prune(),
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
config: {
|
|
41
|
-
name: "config",
|
|
42
|
-
description: "Set CLI configurations.",
|
|
43
|
-
commands: {
|
|
44
|
-
set: {
|
|
45
|
-
name: "set",
|
|
46
|
-
description: "Set configuration.",
|
|
47
|
-
action: (key, value) => void library_1.default.config.set(key, value),
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
const ping = () => {
|
|
53
|
-
commander_1.program
|
|
54
|
-
.command(COMMANDS.ping.name)
|
|
55
|
-
.description(COMMANDS.ping.description)
|
|
56
|
-
.action(COMMANDS.ping.action);
|
|
57
|
-
};
|
|
58
|
-
const labels = () => {
|
|
59
|
-
const labels = commander_1.program
|
|
60
|
-
.command(COMMANDS.labels.name)
|
|
61
|
-
.description(COMMANDS.labels.description);
|
|
62
|
-
labels.addCommand(new commander_1.Command(COMMANDS.labels.commands.list.name)
|
|
63
|
-
.description(COMMANDS.labels.commands.list.description)
|
|
64
|
-
.action(COMMANDS.labels.commands.list.action));
|
|
65
|
-
labels.addCommand(new commander_1.Command(COMMANDS.labels.commands.pull.name)
|
|
66
|
-
.description(COMMANDS.labels.commands.pull.description)
|
|
67
|
-
.action(COMMANDS.labels.commands.pull.action));
|
|
68
|
-
labels.addCommand(new commander_1.Command(COMMANDS.labels.commands.push.name)
|
|
69
|
-
.description(COMMANDS.labels.commands.push.description)
|
|
70
|
-
.action(COMMANDS.labels.commands.push.action));
|
|
71
|
-
labels.addCommand(new commander_1.Command(COMMANDS.labels.commands.prune.name)
|
|
72
|
-
.description(COMMANDS.labels.commands.prune.description)
|
|
73
|
-
.action(COMMANDS.labels.commands.prune.action));
|
|
74
|
-
};
|
|
75
|
-
const config = () => {
|
|
76
|
-
const config = commander_1.program
|
|
77
|
-
.command(COMMANDS.config.name)
|
|
78
|
-
.description(COMMANDS.config.description);
|
|
79
|
-
config.addCommand(new commander_1.Command(COMMANDS.config.commands.set.name)
|
|
80
|
-
.description(COMMANDS.config.commands.set.description)
|
|
81
|
-
.arguments("<key> <value>")
|
|
82
|
-
.action((key, value) => COMMANDS.config.commands.set.action(key, value)));
|
|
83
|
-
};
|
|
84
|
-
const init = () => {
|
|
85
|
-
ping();
|
|
86
|
-
labels();
|
|
87
|
-
config();
|
|
88
|
-
};
|
|
89
|
-
exports.default = init;
|
package/dist/app/config.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const functions_1 = __importDefault(require("./functions"));
|
|
7
|
-
require("dotenv/config");
|
|
8
|
-
const config = {
|
|
9
|
-
repo: process.env.GHITGUD_GITHUB_REPO || (functions_1.default === null || functions_1.default === void 0 ? void 0 : functions_1.default.config.read("repo")),
|
|
10
|
-
token: process.env.GHITGUD_GITHUB_TOKEN || (functions_1.default === null || functions_1.default === void 0 ? void 0 : functions_1.default.config.read("token")),
|
|
11
|
-
};
|
|
12
|
-
exports.default = config;
|
package/dist/app/functions.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const config_1 = __importDefault(require("./config"));
|
|
10
|
-
require("dotenv/config");
|
|
11
|
-
const STATUS_OK = 200;
|
|
12
|
-
const STATUS_UNAUTHORIZED = 401;
|
|
13
|
-
const STATUS_NOT_FOUND = 404;
|
|
14
|
-
const STATUS_UNPROCESSABLE = 422;
|
|
15
|
-
const ENCODING = "utf8";
|
|
16
|
-
const CREDENTIALS_FILE = "credentials.json";
|
|
17
|
-
const GHITGUD_FOLDER = path_1.default.join(os_1.default.homedir(), ".config", "ghitgud");
|
|
18
|
-
const http = {
|
|
19
|
-
isOk: (status) => status === STATUS_OK,
|
|
20
|
-
isNotFound: (status) => status === STATUS_NOT_FOUND,
|
|
21
|
-
isNotAuthorized: (status) => status === STATUS_UNAUTHORIZED,
|
|
22
|
-
isUnprocessable: (status) => status === STATUS_UNPROCESSABLE,
|
|
23
|
-
};
|
|
24
|
-
const environment = {
|
|
25
|
-
hasRepo: () => (config_1.default.repo ? true : false),
|
|
26
|
-
hasToken: () => (config_1.default.token ? true : false),
|
|
27
|
-
};
|
|
28
|
-
const config = {
|
|
29
|
-
read: (key) => {
|
|
30
|
-
if (!fs_1.default.existsSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`))
|
|
31
|
-
return null;
|
|
32
|
-
const data = fs_1.default.readFileSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`, ENCODING);
|
|
33
|
-
const content = JSON.parse(data);
|
|
34
|
-
return content[key];
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
exports.default = { http, environment, config };
|
package/dist/app/ghitgud.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const process_1 = __importDefault(require("process"));
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const ascii_1 = __importDefault(require("./ascii"));
|
|
9
|
-
const commands_1 = __importDefault(require("./commands"));
|
|
10
|
-
const NAME = "ghitgud";
|
|
11
|
-
const VERSION = "1.0.2";
|
|
12
|
-
const DESCRIPTION = "A simple CLI to give superpowers to GitHub.";
|
|
13
|
-
commander_1.program
|
|
14
|
-
.name(NAME)
|
|
15
|
-
.description(DESCRIPTION)
|
|
16
|
-
.version(VERSION);
|
|
17
|
-
(0, commands_1.default)();
|
|
18
|
-
commander_1.program.addHelpText("before", ascii_1.default);
|
|
19
|
-
commander_1.program.parse(process_1.default.argv);
|
package/dist/app/library.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const os_1 = __importDefault(require("os"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const api_1 = __importDefault(require("./api"));
|
|
19
|
-
const functions_1 = __importDefault(require("./functions"));
|
|
20
|
-
const ENCODING = "utf8";
|
|
21
|
-
const PING_RESPONSE = "pong";
|
|
22
|
-
const METADATA_FILE = "labels.json";
|
|
23
|
-
const ERROR_NO_METADATA = "No metadata file found.";
|
|
24
|
-
const CREDENTIALS_FILE = "credentials.json";
|
|
25
|
-
const ERROR_UNSUPPORTED_KEY = "Trying to set unsupported key.";
|
|
26
|
-
const GHITGUD_FOLDER = path_1.default.join(os_1.default.homedir(), ".config", "ghitgud");
|
|
27
|
-
const ping = () => {
|
|
28
|
-
console.info(PING_RESPONSE);
|
|
29
|
-
return { success: true };
|
|
30
|
-
};
|
|
31
|
-
const labels = {
|
|
32
|
-
list: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
const response = yield api_1.default.labels.fetch();
|
|
34
|
-
const data = yield response.json();
|
|
35
|
-
const labels = data.map((label) => ({
|
|
36
|
-
name: label.name,
|
|
37
|
-
color: label.color,
|
|
38
|
-
description: label.description,
|
|
39
|
-
}));
|
|
40
|
-
const result = { success: true, metadata: labels };
|
|
41
|
-
console.info(result);
|
|
42
|
-
return result;
|
|
43
|
-
}),
|
|
44
|
-
pull: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
const response = yield api_1.default.labels.fetch();
|
|
46
|
-
const data = yield response.json();
|
|
47
|
-
const labels = data.map((label) => ({
|
|
48
|
-
name: label.name,
|
|
49
|
-
color: label.color,
|
|
50
|
-
description: label.description,
|
|
51
|
-
}));
|
|
52
|
-
try {
|
|
53
|
-
fs_1.default.mkdirSync(GHITGUD_FOLDER, { recursive: true });
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
fs_1.default.writeFileSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`, JSON.stringify(labels, null, 2));
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
|
63
|
-
}
|
|
64
|
-
const result = { success: true };
|
|
65
|
-
console.info(result);
|
|
66
|
-
return result;
|
|
67
|
-
}),
|
|
68
|
-
push: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
-
if (!fs_1.default.existsSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`))
|
|
70
|
-
throw new Error(ERROR_NO_METADATA);
|
|
71
|
-
const data = fs_1.default.readFileSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`, ENCODING);
|
|
72
|
-
const labels = JSON.parse(data);
|
|
73
|
-
yield Promise.all(labels.map((label) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
-
const response = yield api_1.default.labels.get(label.name);
|
|
75
|
-
if (functions_1.default.http.isOk(response.status))
|
|
76
|
-
yield api_1.default.labels.patch(label);
|
|
77
|
-
if (functions_1.default.http.isNotFound(response.status))
|
|
78
|
-
yield api_1.default.labels.create(label);
|
|
79
|
-
})));
|
|
80
|
-
const result = { success: true };
|
|
81
|
-
console.info(result);
|
|
82
|
-
return result;
|
|
83
|
-
}),
|
|
84
|
-
prune: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
-
if (!fs_1.default.existsSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`))
|
|
86
|
-
throw new Error(ERROR_NO_METADATA);
|
|
87
|
-
const data = fs_1.default.readFileSync(`${GHITGUD_FOLDER}/${METADATA_FILE}`, ENCODING);
|
|
88
|
-
const labels = JSON.parse(data);
|
|
89
|
-
labels.map((label) => __awaiter(void 0, void 0, void 0, function* () { return yield api_1.default.labels.delete(label.name); }));
|
|
90
|
-
const result = { success: true };
|
|
91
|
-
console.info(result);
|
|
92
|
-
return result;
|
|
93
|
-
}),
|
|
94
|
-
};
|
|
95
|
-
const config = {
|
|
96
|
-
set: (key, value) => {
|
|
97
|
-
const knowns = ["token", "repo"];
|
|
98
|
-
if (!knowns.includes(key))
|
|
99
|
-
throw new Error(ERROR_UNSUPPORTED_KEY);
|
|
100
|
-
if (!fs_1.default.existsSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`)) {
|
|
101
|
-
const credentials = { [key]: value };
|
|
102
|
-
try {
|
|
103
|
-
fs_1.default.mkdirSync(GHITGUD_FOLDER, { recursive: true });
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
|
107
|
-
}
|
|
108
|
-
fs_1.default.writeFileSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`, JSON.stringify(credentials, null, 2));
|
|
109
|
-
return { success: true };
|
|
110
|
-
}
|
|
111
|
-
const data = fs_1.default.readFileSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`, ENCODING);
|
|
112
|
-
const credentials = JSON.parse(data);
|
|
113
|
-
credentials[key] = value;
|
|
114
|
-
fs_1.default.writeFileSync(`${GHITGUD_FOLDER}/${CREDENTIALS_FILE}`, JSON.stringify(credentials, null, 2));
|
|
115
|
-
return { success: true };
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
exports.default = {
|
|
119
|
-
ping,
|
|
120
|
-
labels,
|
|
121
|
-
config,
|
|
122
|
-
};
|
package/dist/app/types.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const vitest_1 = require("vitest");
|
|
16
|
-
const api_1 = __importDefault(require("../app/api"));
|
|
17
|
-
const library_1 = __importDefault(require("../app/library"));
|
|
18
|
-
vitest_1.vi.mock("../app/api", () => ({
|
|
19
|
-
default: {
|
|
20
|
-
labels: {
|
|
21
|
-
get: vitest_1.vi.fn(),
|
|
22
|
-
fetch: vitest_1.vi.fn(),
|
|
23
|
-
patch: vitest_1.vi.fn(),
|
|
24
|
-
create: vitest_1.vi.fn(),
|
|
25
|
-
delete: vitest_1.vi.fn(),
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
29
|
-
const API_LABELS = [
|
|
30
|
-
{
|
|
31
|
-
id: 1,
|
|
32
|
-
name: "feature",
|
|
33
|
-
color: "ffffff",
|
|
34
|
-
description: "This is a feature.",
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
const METADATA_LABELS = [
|
|
38
|
-
{
|
|
39
|
-
name: "feature",
|
|
40
|
-
color: "ffffff",
|
|
41
|
-
description: "This is a feature.",
|
|
42
|
-
},
|
|
43
|
-
];
|
|
44
|
-
(0, vitest_1.describe)("ping", () => {
|
|
45
|
-
(0, vitest_1.it)("should return a pong", () => {
|
|
46
|
-
const spy = vitest_1.vi.spyOn(console, "info");
|
|
47
|
-
library_1.default.ping();
|
|
48
|
-
(0, vitest_1.expect)(spy).toHaveBeenCalledWith("pong");
|
|
49
|
-
(0, vitest_1.expect)(library_1.default.ping()).toEqual({ success: true });
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
(0, vitest_1.describe)("labels", () => {
|
|
53
|
-
(0, vitest_1.it)("should list labels", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const mockResponse = { json: () => Promise.resolve(API_LABELS) };
|
|
55
|
-
api_1.default.labels.fetch.mockResolvedValue(mockResponse);
|
|
56
|
-
const result = yield library_1.default.labels.list();
|
|
57
|
-
(0, vitest_1.expect)(result).toEqual({ success: true, metadata: METADATA_LABELS });
|
|
58
|
-
}));
|
|
59
|
-
(0, vitest_1.it)("should pull labels", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
const mockResponse = { json: () => Promise.resolve(API_LABELS) };
|
|
61
|
-
api_1.default.labels.fetch.mockResolvedValue(mockResponse);
|
|
62
|
-
const result = yield library_1.default.labels.pull();
|
|
63
|
-
(0, vitest_1.expect)(result).toEqual({ success: true });
|
|
64
|
-
}));
|
|
65
|
-
(0, vitest_1.it)("should push labels", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
const mockResponse = { status: 200 };
|
|
67
|
-
api_1.default.labels.get.mockResolvedValue(mockResponse);
|
|
68
|
-
const result = yield library_1.default.labels.push();
|
|
69
|
-
(0, vitest_1.expect)(result).toEqual({ success: true });
|
|
70
|
-
}));
|
|
71
|
-
(0, vitest_1.it)("should prune labels", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
-
const result = yield library_1.default.labels.prune();
|
|
73
|
-
(0, vitest_1.expect)(result).toEqual({ success: true });
|
|
74
|
-
}));
|
|
75
|
-
});
|
|
76
|
-
(0, vitest_1.describe)("config", () => {
|
|
77
|
-
(0, vitest_1.it)("should set a config", () => {
|
|
78
|
-
const result = library_1.default.config.set("token", "test");
|
|
79
|
-
(0, vitest_1.expect)(result).toEqual({ success: true });
|
|
80
|
-
});
|
|
81
|
-
});
|
package/scripts/clean.sh
DELETED
package/tests/library.test.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, Mock } from "vitest";
|
|
2
|
-
|
|
3
|
-
import api from "../app/api";
|
|
4
|
-
import library from "../app/library";
|
|
5
|
-
|
|
6
|
-
vi.mock("../app/api", () => ({
|
|
7
|
-
default: {
|
|
8
|
-
labels: {
|
|
9
|
-
get: vi.fn(),
|
|
10
|
-
fetch: vi.fn(),
|
|
11
|
-
patch: vi.fn(),
|
|
12
|
-
create: vi.fn(),
|
|
13
|
-
delete: vi.fn(),
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const API_LABELS = [
|
|
19
|
-
{
|
|
20
|
-
id: 1,
|
|
21
|
-
name: "feature",
|
|
22
|
-
color: "ffffff",
|
|
23
|
-
description: "This is a feature.",
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
const METADATA_LABELS = [
|
|
28
|
-
{
|
|
29
|
-
name: "feature",
|
|
30
|
-
color: "ffffff",
|
|
31
|
-
description: "This is a feature.",
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
describe("ping", () => {
|
|
36
|
-
it("should return a pong", () => {
|
|
37
|
-
const spy = vi.spyOn(console, "info");
|
|
38
|
-
library.ping();
|
|
39
|
-
expect(spy).toHaveBeenCalledWith("pong");
|
|
40
|
-
expect(library.ping()).toEqual({ success: true });
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("labels", () => {
|
|
45
|
-
it("should list labels", async () => {
|
|
46
|
-
const mockResponse = { json: () => Promise.resolve(API_LABELS) };
|
|
47
|
-
(api.labels.fetch as Mock).mockResolvedValue(mockResponse);
|
|
48
|
-
const result = await library.labels.list();
|
|
49
|
-
expect(result).toEqual({ success: true, metadata: METADATA_LABELS });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should pull labels", async () => {
|
|
53
|
-
const mockResponse = { json: () => Promise.resolve(API_LABELS) };
|
|
54
|
-
(api.labels.fetch as Mock).mockResolvedValue(mockResponse);
|
|
55
|
-
const result = await library.labels.pull();
|
|
56
|
-
expect(result).toEqual({ success: true });
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should push labels", async () => {
|
|
60
|
-
const mockResponse = { status: 200 };
|
|
61
|
-
(api.labels.get as Mock).mockResolvedValue(mockResponse);
|
|
62
|
-
const result = await library.labels.push();
|
|
63
|
-
expect(result).toEqual({ success: true });
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("should prune labels", async () => {
|
|
67
|
-
const result = await library.labels.prune();
|
|
68
|
-
expect(result).toEqual({ success: true });
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("config", () => {
|
|
73
|
-
it("should set a config", () => {
|
|
74
|
-
const result = library.config.set("token", "test");
|
|
75
|
-
expect(result).toEqual({ success: true });
|
|
76
|
-
});
|
|
77
|
-
});
|