repo-util 1.9.8 → 1.11.1
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 +5 -0
- package/package.json +9 -9
- package/src/repo-util-cli.mjs +62 -95
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repo-util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 2m tests/*.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"aggregation-repository-provider": "^
|
|
25
|
-
"bitbucket-repository-provider": "^3.9.
|
|
24
|
+
"aggregation-repository-provider": "^4.0.6",
|
|
25
|
+
"bitbucket-repository-provider": "^3.9.11",
|
|
26
26
|
"commander": "^8.3.0",
|
|
27
|
-
"gitea-repository-provider": "^1.16.
|
|
28
|
-
"github-repository-provider": "^7.23.
|
|
29
|
-
"local-repository-provider": "^7.0.
|
|
27
|
+
"gitea-repository-provider": "^1.16.41",
|
|
28
|
+
"github-repository-provider": "^7.23.41",
|
|
29
|
+
"local-repository-provider": "^7.0.106"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"ava": "^3.15.0",
|
|
33
33
|
"c8": "^7.10.0",
|
|
34
|
-
"execa": "^
|
|
35
|
-
"semantic-release": "^18.0.
|
|
34
|
+
"execa": "^6.0.0",
|
|
35
|
+
"semantic-release": "^18.0.1"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
|
-
"node": ">=16.
|
|
38
|
+
"node": ">=16.13.0"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
package/src/repo-util-cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from "fs";
|
|
4
|
-
import program from "commander";
|
|
4
|
+
import program, { Option } from "commander";
|
|
5
5
|
import AggregationProvider from "aggregation-repository-provider";
|
|
6
6
|
import { asArray } from "repository-provider";
|
|
7
7
|
|
|
@@ -33,106 +33,49 @@ program
|
|
|
33
33
|
})
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
program
|
|
37
|
-
.command("providers")
|
|
38
|
-
.option("--json", "output as json")
|
|
39
|
-
.action(async options => {
|
|
40
|
-
const provider = await prepareProvider();
|
|
41
|
-
console.log(
|
|
42
|
-
[
|
|
43
|
-
...provider.providers.map(
|
|
44
|
-
p => `${p.name}: ${JSON.stringify(p.toJSON())}`
|
|
45
|
-
)
|
|
46
|
-
].join("\n")
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
36
|
for (const o of [
|
|
51
|
-
["
|
|
52
|
-
["
|
|
53
|
-
["
|
|
37
|
+
["provider", "providers", ["name"]],
|
|
38
|
+
["group", "repositoryGroups", ["name"]],
|
|
39
|
+
["repository", "repositories", ["fullName"]],
|
|
40
|
+
["branch", "branches", ["fullName"]],
|
|
41
|
+
["hook", "hooks", ["url"]],
|
|
42
|
+
[
|
|
43
|
+
"pull-request",
|
|
44
|
+
"pullRequests",
|
|
45
|
+
["url"],
|
|
46
|
+
{ merge: { description: "merge the pr", execute: pr => pr.merge() } }
|
|
47
|
+
]
|
|
54
48
|
]) {
|
|
55
|
-
program
|
|
56
|
-
|
|
49
|
+
const command = program.command(`${o[0]} [name...]`);
|
|
50
|
+
|
|
51
|
+
command
|
|
57
52
|
.option("--json", "output as json")
|
|
58
|
-
.
|
|
59
|
-
|
|
53
|
+
.option("-a, --attribute <attributes>", "list attribute", a =>
|
|
54
|
+
a.split(",")
|
|
60
55
|
);
|
|
61
|
-
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
.command("hooks <name...>")
|
|
65
|
-
.option("--json", "output as json")
|
|
66
|
-
.action(async (names, options) => {
|
|
67
|
-
const provider = await prepareProvider();
|
|
68
|
-
|
|
69
|
-
if (options.json) {
|
|
70
|
-
const json = [];
|
|
71
|
-
|
|
72
|
-
for await (const repository of provider.repositories(names)) {
|
|
73
|
-
const r = { name: repository.fullName, hooks: [] };
|
|
74
|
-
for await (const hook of repository.hooks()) {
|
|
75
|
-
r.hooks.push(hook);
|
|
76
|
-
}
|
|
57
|
+
const actions = o[3];
|
|
77
58
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
console.log(JSON.stringify(json));
|
|
83
|
-
} else {
|
|
84
|
-
for await (const repository of provider.repositories(names)) {
|
|
85
|
-
for await (const hook of repository.hooks()) {
|
|
86
|
-
console.log(repository.fullName);
|
|
87
|
-
console.log(" " + hook.url);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
59
|
+
if (actions) {
|
|
60
|
+
for (const [an, options] of Object.entries(actions)) {
|
|
61
|
+
command.addOption(new Option(`--${an}`, options.description));
|
|
90
62
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
program
|
|
94
|
-
.command("pull-request <names...>")
|
|
95
|
-
.option("--json", "output as json")
|
|
96
|
-
.option("--merge", "merge the pr")
|
|
97
|
-
.action(async (names, options) => {
|
|
98
|
-
const provider = await prepareProvider();
|
|
99
|
-
|
|
100
|
-
const json = [];
|
|
101
|
-
|
|
102
|
-
for await (const repository of provider.repositories(names)) {
|
|
103
|
-
if (!repository.isArchived) {
|
|
104
|
-
for await (const pr of repository.pullRequestClass.list(repository)) {
|
|
105
|
-
if (options.json) {
|
|
106
|
-
json.push(pr);
|
|
107
|
-
} else {
|
|
108
|
-
console.log(`${pr.identifier}: ${pr.url}`);
|
|
109
|
-
}
|
|
110
|
-
if (options.merge) {
|
|
111
|
-
await pr.merge();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (options.json) {
|
|
118
|
-
console.log(JSON.stringify(json));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
63
|
+
}
|
|
121
64
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
65
|
+
command.action(async (names, options) =>
|
|
66
|
+
list(
|
|
67
|
+
await prepareProvider(options),
|
|
68
|
+
names,
|
|
69
|
+
options,
|
|
70
|
+
o[1],
|
|
71
|
+
options.attribute ? options.attribute : o[2],
|
|
72
|
+
actions
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
133
76
|
|
|
134
77
|
program
|
|
135
|
-
.command("create-repository <
|
|
78
|
+
.command("create-repository <name...>")
|
|
136
79
|
.action(async (names, options) => {
|
|
137
80
|
const provider = await prepareProvider();
|
|
138
81
|
for (const name of names) {
|
|
@@ -142,16 +85,40 @@ program
|
|
|
142
85
|
|
|
143
86
|
program.parse(process.argv);
|
|
144
87
|
|
|
145
|
-
|
|
88
|
+
function normalize(names) {
|
|
89
|
+
return names.length === 0 ? ["*"] : names;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function list(provider, names, options, slot, attributes, actions) {
|
|
146
93
|
if (options.json) {
|
|
147
94
|
const json = [];
|
|
148
|
-
for await (const object of provider[slot](
|
|
95
|
+
for await (const object of provider[slot](normalize(names))) {
|
|
149
96
|
json.push(object);
|
|
150
97
|
}
|
|
151
98
|
console.log(JSON.stringify(json));
|
|
152
99
|
} else {
|
|
153
|
-
for await (const object of provider[slot](
|
|
154
|
-
|
|
100
|
+
for await (const object of provider[slot](normalize(names))) {
|
|
101
|
+
for (const action of Object.keys(actions)) {
|
|
102
|
+
if (options[action]) {
|
|
103
|
+
await actions[action].execute();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// modify
|
|
108
|
+
if (Object.keys(properties).length > 0) {
|
|
109
|
+
for (const [k, v] of Object.entries(properties)) {
|
|
110
|
+
object[k] = v;
|
|
111
|
+
}
|
|
112
|
+
await object.update();
|
|
113
|
+
} else {
|
|
114
|
+
let prefix = "";
|
|
115
|
+
if (object.repository) {
|
|
116
|
+
prefix = object.repository.fullName + ": ";
|
|
117
|
+
}
|
|
118
|
+
for (const a of attributes) {
|
|
119
|
+
console.log(prefix, object[a]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
155
122
|
}
|
|
156
123
|
}
|
|
157
124
|
}
|