@evanpurkhiser/tooling-personal 1.30.0 → 1.32.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/dist/assignees.js CHANGED
@@ -7,6 +7,7 @@ exports.selectAssignee = exports.AssigneeType = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const fast_merge_async_iterators_1 = __importDefault(require("fast-merge-async-iterators"));
9
9
  const graphql_request_1 = require("graphql-request");
10
+ const config_1 = require("./config");
10
11
  const fzf_1 = require("./fzf");
11
12
  const graphql_1 = require("./graphql");
12
13
  var AssigneeType;
@@ -76,6 +77,9 @@ async function* getAssignees(repo) {
76
77
  const items = !isOrganization
77
78
  ? userAssignees
78
79
  : fast_merge_async_iterators_1.default(userAssignees, teamAssignees);
80
+ const assigneeesToIgnore = config_1.config
81
+ .get('ignoreAssignees')
82
+ .map(value => new RegExp(value));
79
83
  for await (const result of items) {
80
84
  const assignees = isUser(result)
81
85
  ? result.repository.assignableUsers.nodes.map(user => ({
@@ -90,7 +94,9 @@ async function* getAssignees(repo) {
90
94
  slug: team.combinedSlug,
91
95
  name: team.name,
92
96
  }));
93
- yield* assignees;
97
+ // Remove assignees that are ignored
98
+ const filteredAssignees = assignees.filter(assignee => !assigneeesToIgnore.some(r => r.test(assignee.slug)));
99
+ yield* filteredAssignees;
94
100
  }
95
101
  }
96
102
  /**
package/dist/cmd/pr.js CHANGED
@@ -143,30 +143,57 @@ async function pr(argv) {
143
143
  console.log(chalk_1.default.red `Missing PR title, aborting`);
144
144
  process.exit(1);
145
145
  }
146
- // 06. Create a Pull Request
147
- const pr = pulls_1.createPull({
148
- baseRefName: defaultBranch,
149
- headRefName: branchName,
150
- repositoryId: repoId,
151
- draft: argv.draft,
152
- title,
153
- body,
146
+ const createPrTask = async (ctx) => {
147
+ const pr = await pulls_1.createPull({
148
+ baseRefName: defaultBranch,
149
+ headRefName: branchName,
150
+ repositoryId: repoId,
151
+ draft: argv.draft,
152
+ title,
153
+ body,
154
+ });
155
+ ctx.pr = pr.createPullRequest.pullRequest;
156
+ };
157
+ const setAutoMergeTask = async (ctx, task) => {
158
+ const pullRequestId = ctx.pr.id;
159
+ try {
160
+ await pulls_1.enableAutoMerge({ pullRequestId, mergeMethod: 'SQUASH' });
161
+ }
162
+ catch (err) {
163
+ task.skip('Auto Merge not available');
164
+ }
165
+ };
166
+ const prTasks = new listr2_1.Listr([], { rendererOptions });
167
+ // 06-a. Create a Pull Request
168
+ prTasks.add({
169
+ title: 'Creating Pull Request',
170
+ task: createPrTask,
171
+ });
172
+ // 06-a. Enable auto merge
173
+ prTasks.add({
174
+ enabled: !!argv.autoMerge,
175
+ title: 'Enabling auto merge',
176
+ task: setAutoMergeTask,
154
177
  });
178
+ const asyncPrTasks = prTasks.run();
179
+ // Do not let asyncPrTasks interfere with assignee selection
180
+ process.stdout.cork();
155
181
  const reviewers = await assignees_1.selectAssignee(repo);
156
- const { createPullRequest } = await pr;
182
+ const { pr } = await asyncPrTasks;
183
+ process.stdout.uncork();
157
184
  // 07. Request reviews
158
185
  const reviewRequestTask = new listr2_1.Listr([], { rendererOptions });
159
186
  reviewRequestTask.add({
160
187
  enabled: () => reviewers.length > 0,
161
188
  title: 'Requesting Reviewers',
162
189
  task: () => pulls_1.requestReview({
163
- pullRequestId: createPullRequest.pullRequest.id,
190
+ pullRequestId: pr.id,
164
191
  userIds: reviewers.filter(a => a.type === assignees_1.AssigneeType.User).map(a => a.id),
165
192
  teamIds: reviewers.filter(a => a.type === assignees_1.AssigneeType.Team).map(a => a.id),
166
193
  }),
167
194
  });
168
195
  await reviewRequestTask.run();
169
196
  // 08. Open in browser
170
- open_1.default(createPullRequest.pullRequest.url);
197
+ open_1.default(pr.url);
171
198
  }
172
199
  exports.pr = pr;
package/dist/config.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.config = void 0;
7
+ const convict_1 = __importDefault(require("convict"));
8
+ const js_yaml_1 = __importDefault(require("js-yaml"));
9
+ const path_1 = require("path");
10
+ convict_1.default.addParser({ extension: ['yml', 'yaml'], parse: js_yaml_1.default.load });
11
+ const config = convict_1.default({
12
+ ignoreAssignees: {
13
+ doc: 'Assignee names / teams to ignore. Should be a regex expression.',
14
+ format: Array,
15
+ default: [],
16
+ },
17
+ });
18
+ exports.config = config;
19
+ const home = process.env.HOME;
20
+ const configDir = process.env.XDG_CONFIG_HOME || path_1.join(home, '.config');
21
+ config.loadFile(path_1.join(configDir, 'pt', 'config.yml'));
22
+ config.validate();
package/dist/index.js CHANGED
@@ -18,7 +18,17 @@ yargs_1.default(process.argv.slice(2))
18
18
  chalk_1.default.level = args.color ? 3 : 0;
19
19
  }
20
20
  }, true)
21
- .command('pr', 'Create and update PRs', y => y.option('draft', { alias: 'd', boolean: true, desc: 'Create PR as a draft' }), pr_1.pr)
21
+ .command('pr', 'Create and update PRs', y => y
22
+ .option('draft', {
23
+ alias: 'd',
24
+ boolean: true,
25
+ desc: 'Create PR as a draft',
26
+ })
27
+ .option('autoMerge', {
28
+ alias: 'm',
29
+ boolean: true,
30
+ desc: 'Enable auto merge for the PR',
31
+ }), pr_1.pr)
22
32
  .command('select-commit', 'Select a commit hash', select_commit_1.selectCommit)
23
33
  .demandCommand(1, '')
24
34
  .parse();
package/dist/pulls.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requestReview = exports.createPull = exports.getPulls = exports.getRepoInfo = void 0;
3
+ exports.requestReview = exports.enableAutoMerge = exports.createPull = exports.getPulls = exports.getRepoInfo = void 0;
4
4
  const graphql_request_1 = require("graphql-request");
5
5
  const graphql_1 = require("./graphql");
6
6
  async function getRepoInfo(repo) {
@@ -83,6 +83,22 @@ function createPull(input) {
83
83
  return graphql_1.request(prGql, { input });
84
84
  }
85
85
  exports.createPull = createPull;
86
+ /**
87
+ * Enables auto merge for a pull request
88
+ */
89
+ function enableAutoMerge(input) {
90
+ const autoMergeGql = graphql_request_1.gql `
91
+ mutation enableAutoMerge($input: EnablePullRequestAutoMergeInput!) {
92
+ enablePullRequestAutoMerge(input: $input) {
93
+ pullRequest {
94
+ id
95
+ }
96
+ }
97
+ }
98
+ `;
99
+ return graphql_1.request(autoMergeGql, { input });
100
+ }
101
+ exports.enableAutoMerge = enableAutoMerge;
86
102
  /**
87
103
  * Assign reviewers to an existing pull request
88
104
  */
package/dist/utils.js CHANGED
@@ -5,10 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.branchFromMessage = exports.getAccessToken = exports.getBranchNames = exports.getRepoPath = exports.getEmailUsername = exports.getRepoKey = void 0;
7
7
  const git_url_parse_1 = __importDefault(require("git-url-parse"));
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
8
  const simple_git_1 = __importDefault(require("simple-git"));
10
- const fs_1 = require("fs");
11
- const path_1 = __importDefault(require("path"));
9
+ const child_process_1 = require("child_process");
12
10
  /**
13
11
  * Get's the current repo information
14
12
  */
@@ -61,12 +59,15 @@ async function getBranchNames() {
61
59
  }
62
60
  exports.getBranchNames = getBranchNames;
63
61
  /**
64
- * Get's the GitHub Oauth token from the hub config
62
+ * Get's the GitHub Oauth token from the gh auth token command
65
63
  */
66
64
  function getAccessToken() {
67
- const hubFile = path_1.default.join(process.env.XDG_DATA_HOME ?? '~/.local/share', 'tooling-personal', 'auth.yml');
68
- const hubConfig = js_yaml_1.default.load(fs_1.readFileSync(hubFile).toString());
69
- return hubConfig['token'];
65
+ try {
66
+ return child_process_1.execSync('gh auth token').toString().trim();
67
+ }
68
+ catch {
69
+ throw new Error('Cannot get token from `gh auth token`');
70
+ }
70
71
  }
71
72
  exports.getAccessToken = getAccessToken;
72
73
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanpurkhiser/tooling-personal",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "Evan Purkhiser's personal tooling",
5
5
  "repository": "https://github.com/evanpurkhiser/tooling-personal",
6
6
  "author": "Evan Purkhiser",
@@ -11,11 +11,13 @@
11
11
  ],
12
12
  "dependencies": {
13
13
  "@octokit/graphql-schema": "^10.54.0",
14
+ "@types/convict": "^6.1.3",
14
15
  "@types/git-url-parse": "^9.0.1",
15
16
  "@types/js-yaml": "^4.0.2",
16
17
  "@types/node": "^16.3.3",
17
18
  "@types/yargs": "^17.0.2",
18
19
  "chalk": "^4.1.1",
20
+ "convict": "^6.2.4",
19
21
  "fast-merge-async-iterators": "^1.0.5",
20
22
  "git-url-parse": "^11.5.0",
21
23
  "graphql": "^15.5.1",