repo-util 1.10.4 → 1.11.4

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.4",
3
+ "version": "1.11.4",
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": "^4.0.1",
25
- "bitbucket-repository-provider": "^3.9.9",
24
+ "aggregation-repository-provider": "^4.0.12",
25
+ "bitbucket-repository-provider": "^3.10.2",
26
26
  "commander": "^8.3.0",
27
- "gitea-repository-provider": "^1.16.34",
28
- "github-repository-provider": "^7.23.32",
29
- "local-repository-provider": "^7.0.106"
27
+ "gitea-repository-provider": "^1.16.47",
28
+ "github-repository-provider": "^7.24.0",
29
+ "local-repository-provider": "^7.0.110"
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
- "node": ">=16.13.0"
38
+ "node": ">=16.13.1"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",
@@ -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,66 +35,44 @@ program
35
35
 
36
36
  for (const o of [
37
37
  ["provider", "providers", ["name"]],
38
- ["repository-group", "repositoryGroups", ["name"]],
38
+ ["group", "repositoryGroups", ["name"]],
39
39
  ["repository", "repositories", ["fullName"]],
40
40
  ["branch", "branches", ["fullName"]],
41
- ["hook", "hooks", ["url"]]
41
+ ["hook", "hooks", ["url"]],
42
+ [
43
+ "pull-request",
44
+ "pullRequests",
45
+ ["url"],
46
+ { merge: { description: "merge the pr", execute: pr => pr.merge() } }
47
+ ]
42
48
  ]) {
43
- program
44
- .command(`${o[0]} <name...>`)
49
+ const command = program.command(`${o[0]} [name...]`);
50
+
51
+ command
45
52
  .option("--json", "output as json")
46
- .option("-a, --attribute <attributes>", "list attribute", a => a.split(","))
47
- .action(async (names, options) =>
48
- list(
49
- await prepareProvider(options),
50
- names,
51
- options,
52
- o[1],
53
- options.attribute ? options.attribute : o[2]
54
- )
53
+ .option("-a, --attribute <attributes>", "list attribute", a =>
54
+ a.split(",")
55
55
  );
56
- }
57
-
58
- program
59
- .command("pull-request <name...>")
60
- .option("--json", "output as json")
61
- .option("--merge", "merge the pr")
62
- .action(async (names, options) => {
63
- const provider = await prepareProvider();
64
-
65
- const json = [];
66
56
 
67
- for await (const repository of provider.repositories(names)) {
68
- if (!repository.isArchived) {
69
- for await (const pr of repository.pullRequestClass.list(repository)) {
70
- if (options.json) {
71
- json.push(pr);
72
- } else {
73
- console.log(`${pr.identifier}: ${pr.url}`);
74
- }
75
- if (options.merge) {
76
- await pr.merge();
77
- }
78
- }
79
- }
80
- }
57
+ const actions = o[3];
81
58
 
82
- if (options.json) {
83
- console.log(JSON.stringify(json));
59
+ if (actions) {
60
+ for (const [an, options] of Object.entries(actions)) {
61
+ command.addOption(new Option(`--${an}`, options.description));
84
62
  }
85
- });
63
+ }
86
64
 
87
- program
88
- .command("update-repository <name...>")
89
- .action(async (names, options) => {
90
- const provider = await prepareProvider();
91
- for await (const repository of provider.repositories(names)) {
92
- for (const [k, v] of Object.entries(properties)) {
93
- repository[k] = v;
94
- }
95
- await repository.update();
96
- }
97
- });
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
+ }
98
76
 
99
77
  program
100
78
  .command("create-repository <name...>")
@@ -107,21 +85,39 @@ program
107
85
 
108
86
  program.parse(process.argv);
109
87
 
110
- 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) {
111
93
  if (options.json) {
112
94
  const json = [];
113
- for await (const object of provider[slot](name)) {
95
+ for await (const object of provider[slot](normalize(names))) {
114
96
  json.push(object);
115
97
  }
116
98
  console.log(JSON.stringify(json));
117
99
  } else {
118
- for await (const object of provider[slot](name)) {
119
- let prefix= "";
120
- if(object.repository) {
121
- prefix = object.repository.fullName + ": ";
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
+ }
122
105
  }
123
- for (const a of attributes) {
124
- console.log(prefix,object[a]);
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
+ }
125
121
  }
126
122
  }
127
123
  }