repo-util 1.10.3 → 1.11.2

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 CHANGED
@@ -9,6 +9,11 @@
9
9
  operate on remote repositories
10
10
 
11
11
 
12
+ # set description
13
+ ```sh
14
+ repo-util -Ddescription="Configuration only" repository '*/*config'
15
+ ```
16
+
12
17
  # API
13
18
 
14
19
  # install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-util",
3
- "version": "1.10.3",
3
+ "version": "1.11.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,18 +21,18 @@
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": "^4.0.0",
25
- "bitbucket-repository-provider": "^3.9.8",
24
+ "aggregation-repository-provider": "^4.0.6",
25
+ "bitbucket-repository-provider": "^3.10.0",
26
26
  "commander": "^8.3.0",
27
- "gitea-repository-provider": "^1.16.33",
28
- "github-repository-provider": "^7.23.31",
29
- "local-repository-provider": "^7.0.105"
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
34
  "execa": "^6.0.0",
35
- "semantic-release": "^18.0.0"
35
+ "semantic-release": "^18.0.1"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=16.13.0"
@@ -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
 
@@ -35,95 +35,44 @@ program
35
35
 
36
36
  for (const o of [
37
37
  ["provider", "providers", ["name"]],
38
- ["repository-group", "repositoryGroups", ["name"]],
39
- ["repository", "repositories", ["name"]],
40
- ["branch", "branches", ["fullName"]]
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
+ ]
41
48
  ]) {
42
- program
43
- .command(`${o[0]} <name...>`)
49
+ const command = program.command(`${o[0]} [name...]`);
50
+
51
+ command
44
52
  .option("--json", "output as json")
45
- .option("-a, --attribute <attributes>", "list attribute", a => a.split(","))
46
- .action(async (names, options) =>
47
- list(
48
- await prepareProvider(options),
49
- names,
50
- options,
51
- o[1],
52
- options.attribute ? options.attribute : o[2]
53
- )
53
+ .option("-a, --attribute <attributes>", "list attribute", a =>
54
+ a.split(",")
54
55
  );
55
- }
56
-
57
- program
58
- .command("hooks <name...>")
59
- .option("--json", "output as json")
60
- .action(async (names, options) => {
61
- const provider = await prepareProvider();
62
56
 
63
- if (options.json) {
64
- const json = [];
57
+ const actions = o[3];
65
58
 
66
- for await (const repository of provider.repositories(names)) {
67
- const r = { name: repository.fullName, hooks: [] };
68
- for await (const hook of repository.hooks()) {
69
- r.hooks.push(hook);
70
- }
71
-
72
- if (r.hooks.length > 0) {
73
- json.push(r);
74
- }
75
- }
76
- console.log(JSON.stringify(json));
77
- } else {
78
- for await (const repository of provider.repositories(names)) {
79
- for await (const hook of repository.hooks()) {
80
- console.log(repository.fullName);
81
- console.log(" " + hook.url);
82
- }
83
- }
59
+ if (actions) {
60
+ for (const [an, options] of Object.entries(actions)) {
61
+ command.addOption(new Option(`--${an}`, options.description));
84
62
  }
85
- });
86
-
87
- program
88
- .command("pull-request <name...>")
89
- .option("--json", "output as json")
90
- .option("--merge", "merge the pr")
91
- .action(async (names, options) => {
92
- const provider = await prepareProvider();
93
-
94
- const json = [];
95
-
96
- for await (const repository of provider.repositories(names)) {
97
- if (!repository.isArchived) {
98
- for await (const pr of repository.pullRequestClass.list(repository)) {
99
- if (options.json) {
100
- json.push(pr);
101
- } else {
102
- console.log(`${pr.identifier}: ${pr.url}`);
103
- }
104
- if (options.merge) {
105
- await pr.merge();
106
- }
107
- }
108
- }
109
- }
110
-
111
- if (options.json) {
112
- console.log(JSON.stringify(json));
113
- }
114
- });
63
+ }
115
64
 
116
- program
117
- .command("update-repository <name...>")
118
- .action(async (names, options) => {
119
- const provider = await prepareProvider();
120
- for await (const repository of provider.repositories(names)) {
121
- for (const [k, v] of Object.entries(properties)) {
122
- repository[k] = v;
123
- }
124
- await repository.update();
125
- }
126
- });
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
+ }
127
76
 
128
77
  program
129
78
  .command("create-repository <name...>")
@@ -136,17 +85,39 @@ program
136
85
 
137
86
  program.parse(process.argv);
138
87
 
139
- async function list(provider, name, options, slot, attributes) {
88
+ function normalize(names) {
89
+ return names.length === 0 ? ["*"] : names;
90
+ }
91
+
92
+ async function list(provider, names, options, slot, attributes, actions) {
140
93
  if (options.json) {
141
94
  const json = [];
142
- for await (const object of provider[slot](name)) {
95
+ for await (const object of provider[slot](normalize(names))) {
143
96
  json.push(object);
144
97
  }
145
98
  console.log(JSON.stringify(json));
146
99
  } else {
147
- for await (const object of provider[slot](name)) {
148
- for (const a of attributes) {
149
- console.log(object[a]);
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
+ }
150
121
  }
151
122
  }
152
123
  }