repo-util 1.15.8 → 1.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-util",
3
- "version": "1.15.8",
3
+ "version": "1.17.0",
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": "^5.2.11",
24
+ "aggregation-repository-provider": "^5.2.21",
25
25
  "bitbucket-repository-provider": "^4.1.19",
26
26
  "commander": "^9.2.0",
27
- "gitea-repository-provider": "^2.1.40",
28
- "github-repository-provider": "^7.26.28",
29
- "local-repository-provider": "^8.0.6"
27
+ "gitea-repository-provider": "^2.1.49",
28
+ "github-repository-provider": "^7.26.37",
29
+ "local-repository-provider": "^8.0.8"
30
30
  },
31
31
  "devDependencies": {
32
32
  "ava": "^4.2.0",
33
- "c8": "^7.11.2",
33
+ "c8": "^7.11.3",
34
34
  "execa": "^6.1.0",
35
35
  "semantic-release": "^19.0.2"
36
36
  },
37
37
  "engines": {
38
- "node": ">=16.14.2"
38
+ "node": ">=16.15.0"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",
@@ -29,43 +29,82 @@ for (const o of [
29
29
  [
30
30
  "provider",
31
31
  "providers",
32
- ["name", ...Object.keys(visibleAttributes(AggregationProvider))]
32
+ ["fullName", ...Object.keys(visibleAttributes(AggregationProvider))]
33
33
  ],
34
34
  ["group", "repositoryGroups", ["fullName"]],
35
- ["repository", "repositories", ["fullName"]],
35
+ [
36
+ "repository",
37
+ "repositories",
38
+ ["fullName"],
39
+ {
40
+ update: {
41
+ description: "update repository attributes",
42
+ executeInstance: async repository => repository.update(properties)
43
+ },
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);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ ],
36
55
  ["branch", "branches", ["fullName"]],
37
56
  ["project", "projects", ["fullName"]],
38
57
  ["milestone", "milestones", ["fullName"]],
58
+ ["application", "applications", ["fullName"]],
39
59
  [
40
60
  "hook",
41
61
  "hooks",
42
62
  ["url", "events", "active"],
43
- { create: { description: "create a hook", execute: () => {} } }
63
+ {
64
+ create: {
65
+ suffix: "<name>",
66
+ description: "create a hook",
67
+ execute: () => {
68
+ console.log("create a hook");
69
+ }
70
+ },
71
+ update: {
72
+ description: "update hook attributes",
73
+ executeInstance: hook => hook.update(properties)
74
+ },
75
+ delete: {
76
+ description: "delete a hook",
77
+ executeInstance: hook => hook.delete()
78
+ }
79
+ }
44
80
  ],
45
81
  [
46
82
  "pull-request",
47
83
  "pullRequests",
48
84
  ["url"],
49
- { merge: { description: "merge the pr", execute: pr => pr.merge() } }
85
+ {
86
+ update: {
87
+ description: "update pr attributes",
88
+ executeInstance: pr => pr.update(properties)
89
+ },
90
+ merge: {
91
+ description: "merge the pr",
92
+ executeInstance: pr => pr.merge()
93
+ },
94
+ decline: {
95
+ description: "decline the pr",
96
+ executeInstance: pr => pr.decline()
97
+ }
98
+ }
50
99
  ]
51
100
  ]) {
52
101
  const command = program.command(`${o[0]} [name...]`);
53
-
54
102
  command
55
103
  .option("--json", "output as json")
56
- .option("--no-identifier", "do not output identifier attributes only")
104
+ .option("--no-identifier", "do not output identifier, show attributes only")
57
105
  .option("-a, --attribute <attributes>", "list attribute", a =>
58
106
  a.split(",")
59
107
  );
60
-
61
- const actions = o[3];
62
-
63
- if (actions) {
64
- for (const [an, options] of Object.entries(actions)) {
65
- command.addOption(new Option(`--${an}`, options.description));
66
- }
67
- }
68
-
69
108
  command.action(async (names, options) =>
70
109
  list(
71
110
  await prepareProvider(options),
@@ -76,16 +115,30 @@ for (const o of [
76
115
  actions
77
116
  )
78
117
  );
79
- }
80
118
 
81
- program
82
- .command("create-repository <name...>")
83
- .action(async (names, options) => {
84
- const provider = await prepareProvider();
85
- for (const name of names) {
86
- await provider.createRepository(name, properties);
119
+ const actions = o[3];
120
+
121
+ if (actions) {
122
+ for (const [an, actionOptions] of Object.entries(actions)) {
123
+ if (actionOptions.execute) {
124
+ const command = program.command(
125
+ `${o[0]}-${an} ${actionOptions.suffix}`
126
+ );
127
+
128
+ command.action(async (names, options) => {
129
+ await actionOptions.execute(
130
+ await prepareProvider(options),
131
+ names,
132
+ options
133
+ );
134
+ });
135
+ }
136
+ if (actionOptions.executeInstance) {
137
+ command.option(`--${an}`, actionOptions.description);
138
+ }
87
139
  }
88
- });
140
+ }
141
+ }
89
142
 
90
143
  program.parse(process.argv);
91
144
 
@@ -99,8 +152,8 @@ async function list(provider, names, options, slot, attributes, actions) {
99
152
  for await (const object of provider[slot](normalize(names))) {
100
153
  if (actions) {
101
154
  for (const [name, action] of Object.entries(actions)) {
102
- if (options[name]) {
103
- await action.execute();
155
+ if (options[name] && action.executeInstance) {
156
+ await action.executeInstance(object, options);
104
157
  }
105
158
  }
106
159
  }
@@ -163,6 +216,8 @@ async function prepareProvider(options) {
163
216
 
164
217
  function visibleAttributes(object) {
165
218
  return Object.fromEntries(
166
- Object.entries(object.attributes).filter(([k, v]) => k!=="name" && !v.private)
219
+ Object.entries(object.attributes).filter(
220
+ ([k, v]) => k !== "name" && !v.private
221
+ )
167
222
  );
168
223
  }