@grunnverk/github-tools 1.0.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/LICENSE +190 -0
- package/README.md +314 -0
- package/dist/errors.js +124 -0
- package/dist/errors.js.map +1 -0
- package/dist/github.js +1406 -0
- package/dist/github.js.map +1 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/issues.js +332 -0
- package/dist/issues.js.map +1 -0
- package/dist/logger.js +15 -0
- package/dist/logger.js.map +1 -0
- package/dist/releaseNotes.js +90 -0
- package/dist/releaseNotes.js.map +1 -0
- package/guide/index.md +78 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Tim O'Brien
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# @grunnverk/github-tools
|
|
2
|
+
|
|
3
|
+
GitHub API utilities for automation - PR management, issue tracking, workflow monitoring.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Pull Request Management** - Create, update, merge, and find PRs
|
|
8
|
+
- **Issue Operations** - Create issues, list open issues, search recent closures
|
|
9
|
+
- **Milestone Management** - Create, close, and find milestones
|
|
10
|
+
- **Release Operations** - Create releases, get releases by tag
|
|
11
|
+
- **Workflow Monitoring** - Wait for workflow completion, get workflow runs
|
|
12
|
+
- **Branch Operations** - Delete branches programmatically
|
|
13
|
+
- **Flexible Logging** - Bring your own logger or use the built-in console logger
|
|
14
|
+
- **Injectable Prompt** - Provide custom prompt functions for interactive operations
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @grunnverk/github-tools
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createPullRequest, mergePullRequest, getRepoDetails } from '@grunnverk/github-tools';
|
|
26
|
+
|
|
27
|
+
// Get repository details
|
|
28
|
+
const { owner, repo } = await getRepoDetails();
|
|
29
|
+
console.log(`Repository: ${owner}/${repo}`);
|
|
30
|
+
|
|
31
|
+
// Create a pull request
|
|
32
|
+
const pr = await createPullRequest(
|
|
33
|
+
'feat: Add new feature',
|
|
34
|
+
'Detailed description of the changes',
|
|
35
|
+
'feature-branch',
|
|
36
|
+
'main'
|
|
37
|
+
);
|
|
38
|
+
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
|
|
39
|
+
|
|
40
|
+
// Merge the pull request
|
|
41
|
+
await mergePullRequest(pr.number, 'squash', 'feat: Add new feature (#123)');
|
|
42
|
+
console.log('PR merged successfully!');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Environment Variables
|
|
46
|
+
|
|
47
|
+
**Required**:
|
|
48
|
+
- `GITHUB_TOKEN`: GitHub personal access token with appropriate permissions
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export GITHUB_TOKEN="ghp_your_token_here"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Custom Logger
|
|
55
|
+
|
|
56
|
+
By default, github-tools uses a console-based logger. You can provide your own logger implementation (e.g., Winston):
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { setLogger } from '@grunnverk/github-tools';
|
|
60
|
+
import winston from 'winston';
|
|
61
|
+
|
|
62
|
+
// Create Winston logger
|
|
63
|
+
const logger = winston.createLogger({
|
|
64
|
+
level: 'info',
|
|
65
|
+
format: winston.format.json(),
|
|
66
|
+
transports: [new winston.transports.Console()]
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Use Winston with github-tools
|
|
70
|
+
setLogger(logger);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Custom Prompt Function
|
|
74
|
+
|
|
75
|
+
For interactive operations (like merge confirmations), you can provide a custom prompt function:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { setPromptFunction } from '@grunnverk/github-tools';
|
|
79
|
+
|
|
80
|
+
// Custom prompt implementation
|
|
81
|
+
const myPrompt = async (message: string): Promise<boolean> => {
|
|
82
|
+
// Your custom prompt logic (e.g., CLI prompts, UI dialogs, etc.)
|
|
83
|
+
const answer = await askUser(message);
|
|
84
|
+
return answer === 'yes';
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Use custom prompt with github-tools
|
|
88
|
+
setPromptFunction(myPrompt);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Core Modules
|
|
92
|
+
|
|
93
|
+
### Pull Request Operations
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import {
|
|
97
|
+
createPullRequest,
|
|
98
|
+
findOpenPullRequestByHeadRef,
|
|
99
|
+
updatePullRequest,
|
|
100
|
+
mergePullRequest
|
|
101
|
+
} from '@grunnverk/github-tools';
|
|
102
|
+
|
|
103
|
+
// Create PR
|
|
104
|
+
const pr = await createPullRequest('title', 'body', 'head', 'base');
|
|
105
|
+
|
|
106
|
+
// Find existing PR
|
|
107
|
+
const existingPr = await findOpenPullRequestByHeadRef('feature-branch');
|
|
108
|
+
|
|
109
|
+
// Update PR
|
|
110
|
+
await updatePullRequest(pr.number, {
|
|
111
|
+
title: 'Updated title',
|
|
112
|
+
body: 'Updated description'
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Merge PR
|
|
116
|
+
await mergePullRequest(pr.number, 'squash', 'Commit title');
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Issue Operations
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import {
|
|
123
|
+
createIssue,
|
|
124
|
+
getOpenIssues,
|
|
125
|
+
getRecentClosedIssuesForCommit
|
|
126
|
+
} from '@grunnverk/github-tools';
|
|
127
|
+
|
|
128
|
+
// Create issue
|
|
129
|
+
const issue = await createIssue(
|
|
130
|
+
'Bug: Something is broken',
|
|
131
|
+
'Detailed description',
|
|
132
|
+
['bug', 'priority-high']
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Get all open issues
|
|
136
|
+
const openIssues = await getOpenIssues();
|
|
137
|
+
|
|
138
|
+
// Get issues closed in recent commits
|
|
139
|
+
const closedIssues = await getRecentClosedIssuesForCommit('v1.0.0', 'v1.1.0', 50);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Milestone Operations
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import {
|
|
146
|
+
findMilestoneByTitle,
|
|
147
|
+
createMilestone,
|
|
148
|
+
closeMilestone
|
|
149
|
+
} from '@grunnverk/github-tools';
|
|
150
|
+
|
|
151
|
+
// Find existing milestone
|
|
152
|
+
const milestone = await findMilestoneByTitle('v1.0.0');
|
|
153
|
+
|
|
154
|
+
// Create new milestone
|
|
155
|
+
const newMilestone = await createMilestone(
|
|
156
|
+
'v1.1.0',
|
|
157
|
+
'Release 1.1.0 milestone'
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Close milestone
|
|
161
|
+
await closeMilestone(milestone.number);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Release Operations
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import {
|
|
168
|
+
createGitHubRelease,
|
|
169
|
+
getReleaseByTag,
|
|
170
|
+
getAllReleases
|
|
171
|
+
} from '@grunnverk/github-tools';
|
|
172
|
+
|
|
173
|
+
// Create release
|
|
174
|
+
await createGitHubRelease(
|
|
175
|
+
'v1.0.0',
|
|
176
|
+
'Release 1.0.0',
|
|
177
|
+
'## Changes\n- Feature 1\n- Feature 2',
|
|
178
|
+
false, // not a draft
|
|
179
|
+
false // not a prerelease
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
// Get specific release
|
|
183
|
+
const release = await getReleaseByTag('v1.0.0');
|
|
184
|
+
|
|
185
|
+
// Get all releases
|
|
186
|
+
const allReleases = await getAllReleases();
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Workflow Operations
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import {
|
|
193
|
+
waitForWorkflowsToComplete,
|
|
194
|
+
getWorkflowRunsForCommit
|
|
195
|
+
} from '@grunnverk/github-tools';
|
|
196
|
+
|
|
197
|
+
// Wait for workflows to complete (with timeout)
|
|
198
|
+
await waitForWorkflowsToComplete('abc123', 300); // 5 minutes
|
|
199
|
+
|
|
200
|
+
// Get workflow runs for a commit
|
|
201
|
+
const runs = await getWorkflowRunsForCommit('abc123');
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## API Documentation
|
|
205
|
+
|
|
206
|
+
### Pull Request Functions
|
|
207
|
+
|
|
208
|
+
| Function | Description |
|
|
209
|
+
|----------|-------------|
|
|
210
|
+
| `createPullRequest(title, body, head, base?)` | Creates a new pull request |
|
|
211
|
+
| `findOpenPullRequestByHeadRef(headRef)` | Finds open PR by head branch |
|
|
212
|
+
| `updatePullRequest(number, updates)` | Updates PR title/body |
|
|
213
|
+
| `mergePullRequest(number, method, title?)` | Merges a pull request |
|
|
214
|
+
| `deleteBranch(branchName)` | Deletes a branch |
|
|
215
|
+
|
|
216
|
+
### Issue Functions
|
|
217
|
+
|
|
218
|
+
| Function | Description |
|
|
219
|
+
|----------|-------------|
|
|
220
|
+
| `createIssue(title, body, labels?)` | Creates a new issue |
|
|
221
|
+
| `getOpenIssues()` | Gets all open issues |
|
|
222
|
+
| `getRecentClosedIssuesForCommit(from, to, limit)` | Gets recently closed issues |
|
|
223
|
+
|
|
224
|
+
### Milestone Functions
|
|
225
|
+
|
|
226
|
+
| Function | Description |
|
|
227
|
+
|----------|-------------|
|
|
228
|
+
| `findMilestoneByTitle(title)` | Finds milestone by title |
|
|
229
|
+
| `createMilestone(title, description?)` | Creates a new milestone |
|
|
230
|
+
| `closeMilestone(number)` | Closes a milestone |
|
|
231
|
+
|
|
232
|
+
### Release Functions
|
|
233
|
+
|
|
234
|
+
| Function | Description |
|
|
235
|
+
|----------|-------------|
|
|
236
|
+
| `createGitHubRelease(tag, name, body, draft, prerelease)` | Creates a GitHub release |
|
|
237
|
+
| `getReleaseByTag(tag)` | Gets release by tag name |
|
|
238
|
+
| `getAllReleases()` | Gets all releases |
|
|
239
|
+
|
|
240
|
+
### Workflow Functions
|
|
241
|
+
|
|
242
|
+
| Function | Description |
|
|
243
|
+
|----------|-------------|
|
|
244
|
+
| `waitForWorkflowsToComplete(sha, timeout?)` | Waits for workflows to complete |
|
|
245
|
+
| `getWorkflowRunsForCommit(sha)` | Gets workflow runs for commit |
|
|
246
|
+
| `getAllWorkflowRuns()` | Gets all workflow runs |
|
|
247
|
+
| `getCheckRunsForRef(ref)` | Gets check runs for a ref |
|
|
248
|
+
|
|
249
|
+
### Utility Functions
|
|
250
|
+
|
|
251
|
+
| Function | Description |
|
|
252
|
+
|----------|-------------|
|
|
253
|
+
| `getOctokit()` | Gets configured Octokit instance |
|
|
254
|
+
| `getCurrentBranchName()` | Gets current branch name |
|
|
255
|
+
| `getRepoDetails()` | Gets owner and repo name |
|
|
256
|
+
| `setLogger(logger)` | Sets custom logger |
|
|
257
|
+
| `setPromptFunction(fn)` | Sets custom prompt function |
|
|
258
|
+
|
|
259
|
+
## Security
|
|
260
|
+
|
|
261
|
+
This library requires a GitHub personal access token with appropriate permissions:
|
|
262
|
+
|
|
263
|
+
- **`repo`** scope for private repositories
|
|
264
|
+
- **`public_repo`** scope for public repositories
|
|
265
|
+
- **`workflow`** scope if you need to interact with GitHub Actions
|
|
266
|
+
|
|
267
|
+
Store your token securely:
|
|
268
|
+
```bash
|
|
269
|
+
# Never commit tokens to version control
|
|
270
|
+
export GITHUB_TOKEN="ghp_your_token_here"
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Development
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Install dependencies
|
|
277
|
+
npm install
|
|
278
|
+
|
|
279
|
+
# Build
|
|
280
|
+
npm run build
|
|
281
|
+
|
|
282
|
+
# Run tests
|
|
283
|
+
npm run test
|
|
284
|
+
|
|
285
|
+
# Lint
|
|
286
|
+
npm run lint
|
|
287
|
+
|
|
288
|
+
# Watch mode
|
|
289
|
+
npm run watch
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Dependencies
|
|
293
|
+
|
|
294
|
+
- **@grunnverk/git-tools**: Git operations and utilities
|
|
295
|
+
- **@octokit/rest**: GitHub API client
|
|
296
|
+
- **winston** (peer, optional): Logging framework
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
Apache-2.0 - see [LICENSE](LICENSE) file for details.
|
|
301
|
+
|
|
302
|
+
## Author
|
|
303
|
+
|
|
304
|
+
Tim O'Brien <tobrien@discursive.com>
|
|
305
|
+
|
|
306
|
+
## Related Projects
|
|
307
|
+
|
|
308
|
+
- [kodrdriv](https://github.com/grunnverk/kodrdriv) - AI-powered Git workflow automation tool
|
|
309
|
+
- [@grunnverk/git-tools](https://github.com/grunnverk/git-tools) - Git utilities for automation
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
TEST
|
|
313
|
+
|
|
314
|
+
<!-- Build: 2026-01-15 15:59:12 UTC -->
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error types for github-tools
|
|
16
|
+
*/ class CommandError extends Error {
|
|
17
|
+
constructor(message){
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'CommandError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class ArgumentError extends Error {
|
|
23
|
+
constructor(message){
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'ArgumentError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class PullRequestCheckError extends Error {
|
|
29
|
+
getRecoveryInstructions() {
|
|
30
|
+
return `To resolve failed PR checks:
|
|
31
|
+
1. Review the failed checks at: ${this.prUrl}
|
|
32
|
+
2. Fix the issues identified
|
|
33
|
+
3. Push the fixes
|
|
34
|
+
4. Re-run this command`;
|
|
35
|
+
}
|
|
36
|
+
constructor(message, prNumber, failedChecks, prUrl){
|
|
37
|
+
super(message), _define_property(this, "prNumber", void 0), _define_property(this, "failedChecks", void 0), _define_property(this, "prUrl", void 0);
|
|
38
|
+
this.name = 'PullRequestCheckError';
|
|
39
|
+
this.prNumber = prNumber || 0;
|
|
40
|
+
this.failedChecks = failedChecks || [];
|
|
41
|
+
this.prUrl = prUrl || '';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class PullRequestCreationError extends Error {
|
|
45
|
+
getRecoveryInstructions() {
|
|
46
|
+
var _this_details;
|
|
47
|
+
if (this.statusCode === 422) {
|
|
48
|
+
var _this_details1;
|
|
49
|
+
const errorMessage = ((_this_details1 = this.details) === null || _this_details1 === void 0 ? void 0 : _this_details1.message) || '';
|
|
50
|
+
// Check for specific 422 error patterns
|
|
51
|
+
if (errorMessage.includes('pull request already exists') || errorMessage.includes('A pull request already exists')) {
|
|
52
|
+
const instructions = [
|
|
53
|
+
`❌ Failed to create PR: A pull request already exists for ${this.head} → ${this.base}`
|
|
54
|
+
];
|
|
55
|
+
if (this.existingPRUrl) {
|
|
56
|
+
instructions.push('');
|
|
57
|
+
instructions.push(`📋 Existing PR: ${this.existingPRUrl}`);
|
|
58
|
+
}
|
|
59
|
+
instructions.push('');
|
|
60
|
+
instructions.push('Options:');
|
|
61
|
+
if (this.existingPRNumber) {
|
|
62
|
+
instructions.push(` 1. Reuse existing PR #${this.existingPRNumber} (command will detect and continue automatically)`);
|
|
63
|
+
instructions.push(` 2. Close existing PR: gh pr close ${this.existingPRNumber}`);
|
|
64
|
+
} else {
|
|
65
|
+
instructions.push(' 1. Check for existing PRs: gh pr list');
|
|
66
|
+
instructions.push(' 2. Close existing PR if needed: gh pr close <number>');
|
|
67
|
+
}
|
|
68
|
+
instructions.push(` 3. Use different branch name`);
|
|
69
|
+
return instructions.join('\n');
|
|
70
|
+
}
|
|
71
|
+
if (errorMessage.includes('No commits between') || errorMessage.includes('head and base')) {
|
|
72
|
+
return `❌ Failed to create PR: No commits between ${this.head} and ${this.base}
|
|
73
|
+
|
|
74
|
+
This usually means:
|
|
75
|
+
• The branches are already in sync
|
|
76
|
+
• No changes have been pushed to ${this.head}
|
|
77
|
+
|
|
78
|
+
What to do:
|
|
79
|
+
1. Verify you're on the correct branch: git branch
|
|
80
|
+
2. Check if there are unpushed commits: git log ${this.base}..${this.head}
|
|
81
|
+
3. If no changes exist, there's nothing to publish`;
|
|
82
|
+
}
|
|
83
|
+
if (errorMessage.includes('Validation Failed') || errorMessage.includes('field')) {
|
|
84
|
+
return `❌ Failed to create PR: Validation error
|
|
85
|
+
|
|
86
|
+
Error details: ${errorMessage}
|
|
87
|
+
|
|
88
|
+
Common causes:
|
|
89
|
+
• PR title too long (max 256 characters)
|
|
90
|
+
• Invalid characters in title or body
|
|
91
|
+
• Branch protection rules preventing PR creation
|
|
92
|
+
|
|
93
|
+
What to do:
|
|
94
|
+
1. Check your commit message is valid: git log -1
|
|
95
|
+
2. Verify branch protection settings in GitHub
|
|
96
|
+
3. Try creating the PR manually to see detailed error`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Generic recovery instructions
|
|
100
|
+
return `❌ Failed to create pull request (HTTP ${this.statusCode})
|
|
101
|
+
|
|
102
|
+
Error: ${((_this_details = this.details) === null || _this_details === void 0 ? void 0 : _this_details.message) || 'Unknown error'}
|
|
103
|
+
|
|
104
|
+
What to do:
|
|
105
|
+
1. Check GitHub API status: https://www.githubstatus.com/
|
|
106
|
+
2. Verify GITHUB_TOKEN permissions (needs 'repo' scope)
|
|
107
|
+
3. Check if base branch (${this.base}) exists
|
|
108
|
+
4. Verify working directory is clean: git status
|
|
109
|
+
5. Try viewing existing PRs: gh pr list --head ${this.head}`;
|
|
110
|
+
}
|
|
111
|
+
constructor(message, statusCode, head, base, details, existingPRNumber, existingPRUrl){
|
|
112
|
+
super(message), _define_property(this, "statusCode", void 0), _define_property(this, "existingPRNumber", void 0), _define_property(this, "existingPRUrl", void 0), _define_property(this, "head", void 0), _define_property(this, "base", void 0), _define_property(this, "details", void 0);
|
|
113
|
+
this.name = 'PullRequestCreationError';
|
|
114
|
+
this.statusCode = statusCode;
|
|
115
|
+
this.head = head;
|
|
116
|
+
this.base = base;
|
|
117
|
+
this.details = details;
|
|
118
|
+
this.existingPRNumber = existingPRNumber;
|
|
119
|
+
this.existingPRUrl = existingPRUrl;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { ArgumentError, CommandError, PullRequestCheckError, PullRequestCreationError };
|
|
124
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Error types for github-tools\n */\n\nexport class CommandError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CommandError';\n }\n}\n\nexport class ArgumentError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ArgumentError';\n }\n}\n\nexport class PullRequestCheckError extends Error {\n public readonly prNumber: number;\n public readonly failedChecks: any[];\n public readonly prUrl: string;\n\n constructor(message: string, prNumber?: number, failedChecks?: any[], prUrl?: string) {\n super(message);\n this.name = 'PullRequestCheckError';\n this.prNumber = prNumber || 0;\n this.failedChecks = failedChecks || [];\n this.prUrl = prUrl || '';\n }\n\n getRecoveryInstructions(): string {\n return `To resolve failed PR checks:\n1. Review the failed checks at: ${this.prUrl}\n2. Fix the issues identified\n3. Push the fixes\n4. Re-run this command`;\n }\n}\n\nexport class PullRequestCreationError extends Error {\n public readonly statusCode: number;\n public readonly existingPRNumber?: number;\n public readonly existingPRUrl?: string;\n public readonly head: string;\n public readonly base: string;\n public readonly details?: any;\n\n constructor(\n message: string,\n statusCode: number,\n head: string,\n base: string,\n details?: any,\n existingPRNumber?: number,\n existingPRUrl?: string\n ) {\n super(message);\n this.name = 'PullRequestCreationError';\n this.statusCode = statusCode;\n this.head = head;\n this.base = base;\n this.details = details;\n this.existingPRNumber = existingPRNumber;\n this.existingPRUrl = existingPRUrl;\n }\n\n getRecoveryInstructions(): string {\n if (this.statusCode === 422) {\n const errorMessage = this.details?.message || '';\n\n // Check for specific 422 error patterns\n if (errorMessage.includes('pull request already exists') ||\n errorMessage.includes('A pull request already exists')) {\n const instructions = [`❌ Failed to create PR: A pull request already exists for ${this.head} → ${this.base}`];\n\n if (this.existingPRUrl) {\n instructions.push('');\n instructions.push(`📋 Existing PR: ${this.existingPRUrl}`);\n }\n\n instructions.push('');\n instructions.push('Options:');\n if (this.existingPRNumber) {\n instructions.push(` 1. Reuse existing PR #${this.existingPRNumber} (command will detect and continue automatically)`);\n instructions.push(` 2. Close existing PR: gh pr close ${this.existingPRNumber}`);\n } else {\n instructions.push(' 1. Check for existing PRs: gh pr list');\n instructions.push(' 2. Close existing PR if needed: gh pr close <number>');\n }\n instructions.push(` 3. Use different branch name`);\n\n return instructions.join('\\n');\n }\n\n if (errorMessage.includes('No commits between') ||\n errorMessage.includes('head and base')) {\n return `❌ Failed to create PR: No commits between ${this.head} and ${this.base}\n\nThis usually means:\n • The branches are already in sync\n • No changes have been pushed to ${this.head}\n\nWhat to do:\n 1. Verify you're on the correct branch: git branch\n 2. Check if there are unpushed commits: git log ${this.base}..${this.head}\n 3. If no changes exist, there's nothing to publish`;\n }\n\n if (errorMessage.includes('Validation Failed') ||\n errorMessage.includes('field')) {\n return `❌ Failed to create PR: Validation error\n\nError details: ${errorMessage}\n\nCommon causes:\n • PR title too long (max 256 characters)\n • Invalid characters in title or body\n • Branch protection rules preventing PR creation\n\nWhat to do:\n 1. Check your commit message is valid: git log -1\n 2. Verify branch protection settings in GitHub\n 3. Try creating the PR manually to see detailed error`;\n }\n }\n\n // Generic recovery instructions\n return `❌ Failed to create pull request (HTTP ${this.statusCode})\n\nError: ${this.details?.message || 'Unknown error'}\n\nWhat to do:\n 1. Check GitHub API status: https://www.githubstatus.com/\n 2. Verify GITHUB_TOKEN permissions (needs 'repo' scope)\n 3. Check if base branch (${this.base}) exists\n 4. Verify working directory is clean: git status\n 5. Try viewing existing PRs: gh pr list --head ${this.head}`;\n }\n}\n\n"],"names":["CommandError","Error","message","name","ArgumentError","PullRequestCheckError","getRecoveryInstructions","prUrl","prNumber","failedChecks","PullRequestCreationError","statusCode","errorMessage","details","includes","instructions","head","base","existingPRUrl","push","existingPRNumber","join"],"mappings":";;;;;;;;;;;;;AAAA;;IAIO,MAAMA,YAAAA,SAAqBC,KAAAA,CAAAA;AAC9B,IAAA,WAAA,CAAYC,OAAe,CAAE;AACzB,QAAA,KAAK,CAACA,OAAAA,CAAAA;QACN,IAAI,CAACC,IAAI,GAAG,cAAA;AAChB,IAAA;AACJ;AAEO,MAAMC,aAAAA,SAAsBH,KAAAA,CAAAA;AAC/B,IAAA,WAAA,CAAYC,OAAe,CAAE;AACzB,QAAA,KAAK,CAACA,OAAAA,CAAAA;QACN,IAAI,CAACC,IAAI,GAAG,eAAA;AAChB,IAAA;AACJ;AAEO,MAAME,qBAAAA,SAA8BJ,KAAAA,CAAAA;IAavCK,uBAAAA,GAAkC;AAC9B,QAAA,OAAO,CAAC;gCACgB,EAAE,IAAI,CAACC,KAAK;;;sBAGtB,CAAC;AACnB,IAAA;AAdA,IAAA,WAAA,CAAYL,OAAe,EAAEM,QAAiB,EAAEC,YAAoB,EAAEF,KAAc,CAAE;AAClF,QAAA,KAAK,CAACL,OAAAA,CAAAA,EALV,gBAAA,CAAA,IAAA,EAAgBM,UAAAA,EAAhB,MAAA,CAAA,EACA,gBAAA,CAAA,IAAA,EAAgBC,cAAAA,EAAhB,MAAA,CAAA,EACA,gBAAA,CAAA,IAAA,EAAgBF,OAAAA,EAAhB,MAAA,CAAA;QAII,IAAI,CAAC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