repo-util 1.19.0 → 1.20.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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/repo-util-cli.mjs +78 -127
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-util",
3
- "version": "1.19.0",
3
+ "version": "1.20.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,12 +21,12 @@
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": "^5.2.23",
25
- "bitbucket-repository-provider": "^4.1.21",
24
+ "aggregation-repository-provider": "^5.2.28",
25
+ "bitbucket-repository-provider": "^4.1.26",
26
26
  "commander": "^9.2.0",
27
- "gitea-repository-provider": "^2.1.53",
28
- "github-repository-provider": "^7.28.1",
29
- "local-repository-provider": "^8.0.9"
27
+ "gitea-repository-provider": "^2.1.60",
28
+ "github-repository-provider": "^7.29.6",
29
+ "local-repository-provider": "^8.0.11"
30
30
  },
31
31
  "devDependencies": {
32
32
  "ava": "^4.2.0",
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { readFileSync } from "fs";
4
4
  import { fileURLToPath } from "url";
5
- import { program, Option } from "commander";
5
+ import { program } from "commander";
6
6
  import {
7
7
  Repository,
8
8
  RepositoryGroup,
@@ -38,110 +38,47 @@ program
38
38
  );
39
39
 
40
40
  for (const o of [
41
- [
42
- "provider",
43
- "providers",
44
- ["fullName", ...Object.keys(visibleAttributes(MultiGroupProvider))],
45
- {
46
- update: {
47
- description: "update provider attributes",
48
- executeInstance: async provider => provider.update(properties)
49
- }
50
- }
51
- ],
52
- [
53
- "group",
54
- "repositoryGroups",
55
- ["fullName", ...Object.keys(visibleAttributes(RepositoryGroup))],
56
- {
57
- update: {
58
- description: "update group attributes",
59
- executeInstance: async group => group.update(properties)
60
- }
61
- }
62
- ],
63
- [
64
- "repository",
65
- "repositories",
66
- ["fullName", ...Object.keys(visibleAttributes(Repository))],
67
- {
68
- update: {
69
- description: "update repository attributes",
70
- executeInstance: async repository => repository.update(properties)
71
- },
72
- create: {
73
- suffix: "<names>",
74
- description: "create repositories",
75
- execute: async (provider, names, options) => {
76
- for (const name of names) {
77
- await provider.createRepository(name, properties);
78
- }
41
+ type(MultiGroupProvider),
42
+ type(RepositoryGroup),
43
+ type(Repository, {
44
+ create: {
45
+ suffix: "<names>",
46
+ description: "create repositories",
47
+ execute: async (provider, names, options) => {
48
+ for (const name of names) {
49
+ await provider.createRepository(name, properties);
79
50
  }
80
51
  }
81
52
  }
82
- ],
83
- [
84
- "branch",
85
- "branches",
86
- ["fullName", ...Object.keys(visibleAttributes(Branch))]
87
- ],
88
- ["tag", "tags", ["fullName", ...Object.keys(visibleAttributes(Tag))]],
89
- [
90
- "project",
91
- "projects",
92
- ["fullName", ...Object.keys(visibleAttributes(Project))]
93
- ],
94
- [
95
- "milestone",
96
- "milestones",
97
- ["fullName", ...Object.keys(visibleAttributes(Milestone))]
98
- ],
99
- [
100
- "application",
101
- "applications",
102
- ["fullName", ...Object.keys(visibleAttributes(Application))]
103
- ],
104
- [
105
- "hook",
106
- "hooks",
107
- ["url", ...Object.keys(visibleAttributes(Hook))],
108
- {
109
- create: {
110
- suffix: "<name>",
111
- description: "create a hook",
112
- execute: () => {
113
- console.log("create a hook");
114
- }
115
- },
116
- update: {
117
- description: "update hook attributes",
118
- executeInstance: hook => hook.update(properties)
119
- },
120
- delete: {
121
- description: "delete a hook",
122
- executeInstance: hook => hook.delete()
53
+ }),
54
+ type(Branch),
55
+ type(Tag),
56
+ type(Project),
57
+ type(Milestone),
58
+ type(Application),
59
+ type(Hook, {
60
+ create: {
61
+ suffix: "<name>",
62
+ description: "create a hook",
63
+ execute: () => {
64
+ console.log("create a hook");
123
65
  }
66
+ },
67
+ delete: {
68
+ description: "delete a hook",
69
+ executeInstance: hook => hook.delete()
124
70
  }
125
- ],
126
- [
127
- "pull-request",
128
- "pullRequests",
129
- ["url", ...Object.keys(visibleAttributes(PullRequest))],
130
- {
131
- update: {
132
- description: "update pr attributes",
133
- executeInstance: pr => pr.update(properties)
134
- },
135
- merge: {
136
- description: "merge the pr",
137
- executeInstance: pr => pr.merge()
138
- },
139
- decline: {
140
- description: "decline the pr",
141
- executeInstance: pr => pr.decline()
142
- }
71
+ }),
72
+ type(PullRequest, {
73
+ merge: {
74
+ description: "merge the pr",
75
+ executeInstance: pr => pr.merge()
76
+ },
77
+ decline: {
78
+ description: "decline the pr",
79
+ executeInstance: pr => pr.decline()
143
80
  }
144
- ]
81
+ })
145
82
  ]) {
146
83
  const command = program.command(`${o[0]} [name...]`);
147
84
  command
@@ -202,36 +139,29 @@ async function list(provider, names, options, slot, attributes, actions) {
202
139
  }
203
140
  }
204
141
  }
205
- // modify
206
- if (Object.keys(properties).length > 0) {
207
- for (const [k, v] of Object.entries(properties)) {
208
- object[k] = v;
209
- }
210
- await object.update();
142
+
143
+ if (options.json) {
144
+ json.push(object);
211
145
  } else {
212
- if (options.json) {
213
- json.push(object);
214
- } else {
215
- for (const a of attributes) {
216
- let value = object[a];
217
- if (Array.isArray(value)) {
218
- value = value.join(" ");
219
- } else if (value instanceof Set) {
220
- value = [...value].join(" ");
221
- } else if (value === undefined) {
222
- value = "";
223
- }
146
+ for (const a of attributes) {
147
+ let value = object[a];
148
+ if (Array.isArray(value)) {
149
+ value = value.join(" ");
150
+ } else if (value instanceof Set) {
151
+ value = [...value].join(" ");
152
+ } else if (value === undefined) {
153
+ value = "";
154
+ }
224
155
 
225
- if (options.identifier === false) {
226
- console.log(value);
227
- } else {
228
- console.log(
229
- attributes.indexOf(a) === 0
230
- ? object.fullName + ":"
231
- : " ".substring(a.length) + a + ":",
232
- value
233
- );
234
- }
156
+ if (options.identifier === false) {
157
+ console.log(value);
158
+ } else {
159
+ console.log(
160
+ attributes.indexOf(a) === 0
161
+ ? object.fullName + ":"
162
+ : " ".substring(a.length) + a + ":",
163
+ value
164
+ );
235
165
  }
236
166
  }
237
167
  }
@@ -266,3 +196,24 @@ function visibleAttributes(object) {
266
196
  )
267
197
  );
268
198
  }
199
+
200
+ function type(clazz, extra) {
201
+ return [
202
+ clazz.type,
203
+ clazz.collectionName,
204
+ ["fullName", ...Object.keys(visibleAttributes(clazz))],
205
+ {
206
+ update: {
207
+ description: `update ${clazz.type} attributes`,
208
+ executeInstance: object => {
209
+ for (const [k, v] of Object.entries(properties)) {
210
+ object[k] = v;
211
+ }
212
+
213
+ object.update();
214
+ }
215
+ },
216
+ ...extra
217
+ }
218
+ ];
219
+ }