repo-util 1.15.9 → 1.16.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.9",
3
+ "version": "1.16.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.15",
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.43",
28
- "github-repository-provider": "^7.26.30",
27
+ "gitea-repository-provider": "^2.1.49",
28
+ "github-repository-provider": "^7.26.37",
29
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",
@@ -32,40 +32,67 @@ for (const o of [
32
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
+ }
44
72
  ],
45
73
  [
46
74
  "pull-request",
47
75
  "pullRequests",
48
76
  ["url"],
49
- { merge: { description: "merge the pr", execute: pr => pr.merge() } }
77
+ {
78
+ update: {
79
+ description: "update pr attributes",
80
+ executeInstance: async pr => pr.update(properties)
81
+ },
82
+ merge: {
83
+ description: "merge the pr",
84
+ executeInstance: async (pr, options) => pr.merge()
85
+ }
86
+ }
50
87
  ]
51
88
  ]) {
52
89
  const command = program.command(`${o[0]} [name...]`);
53
-
54
90
  command
55
91
  .option("--json", "output as json")
56
92
  .option("--no-identifier", "do not output identifier attributes only")
57
93
  .option("-a, --attribute <attributes>", "list attribute", a =>
58
94
  a.split(",")
59
95
  );
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
96
  command.action(async (names, options) =>
70
97
  list(
71
98
  await prepareProvider(options),
@@ -76,16 +103,30 @@ for (const o of [
76
103
  actions
77
104
  )
78
105
  );
79
- }
80
106
 
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);
107
+ const actions = o[3];
108
+
109
+ if (actions) {
110
+ for (const [an, actionOptions] of Object.entries(actions)) {
111
+ if (actionOptions.execute) {
112
+ const command = program.command(
113
+ `${o[0]}-${an} ${actionOptions.suffix}`
114
+ );
115
+
116
+ command.action(async (names, options) => {
117
+ await actionOptions.execute(
118
+ await prepareProvider(options),
119
+ names,
120
+ options
121
+ );
122
+ });
123
+ }
124
+ if (actionOptions.executeInstance) {
125
+ command.option(`--${an}`, actionOptions.description);
126
+ }
87
127
  }
88
- });
128
+ }
129
+ }
89
130
 
90
131
  program.parse(process.argv);
91
132
 
@@ -99,8 +140,8 @@ async function list(provider, names, options, slot, attributes, actions) {
99
140
  for await (const object of provider[slot](normalize(names))) {
100
141
  if (actions) {
101
142
  for (const [name, action] of Object.entries(actions)) {
102
- if (options[name]) {
103
- await action.execute();
143
+ if (options[name] && action.executeInstance) {
144
+ await action.executeInstance(object, options);
104
145
  }
105
146
  }
106
147
  }