-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtypes.ts
221 lines (201 loc) · 5.88 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {CreateCommitOptions} from './github/create-commit';
export type FileMode = '100644' | '100755' | '040000' | '160000' | '120000';
/**
* GitHub definition of tree
*/
export interface TreeObject {
path: string;
mode: FileMode;
type: 'blob' | 'tree' | 'commit';
sha?: string | null;
content?: string;
}
/**
* The content and the mode of a file.
* Default file mode is a text file which has code '100644'.
* If `content` is not null, then `content` must be the entire file content.
* See https://developer.github.com/v3/git/trees/#tree-object for details on mode.
*/
export class FileData {
readonly mode: FileMode;
readonly content: string | null;
constructor(content: string | null, mode: FileMode = '100644') {
this.mode = mode;
this.content = content;
}
}
/**
* The map of a path to its content data.
* The content must be the entire file content.
*/
export type Changes = Map<string, FileData>;
/**
* The domain of a repository
*/
export interface RepoDomain {
repo: string;
owner: string;
}
/**
* The domain for a branch
*/
export interface BranchDomain extends RepoDomain {
branch: string;
}
/**
* The descriptive properties for any entity
*/
export interface Description {
title: string;
body: string;
}
/**
* The user options for creating GitHub PRs
*/
export interface CreatePullRequestUserOptions extends CreateCommitOptions {
// the owner of the target fork repository
upstreamOwner: string;
// the name of the target fork repository
upstreamRepo: string;
// The message of any commits made.
message: string;
// The description of the pull request.
description: string;
// The title of the pull request.
title: string;
// the name of the branch to push changes to. Default is 'code-suggestions'. (optional)
branch?: string;
// Whether or not to force branch reference updates. Default is false. (optional)
force?: boolean;
// Should a fork be used when creating pull request
fork?: boolean;
// Primary upstream branch to open PRs against. Default is 'main' (optional)
primary?: string;
// Whether or not maintainers can modify the PR. Default is true. (optional)
maintainersCanModify?: boolean;
// The list of labels to apply to the newly created PR. Default is empty. (optional)
labels?: string[];
// Number of times to retry if the request fails. Defaults to 5.
retry?: number;
// Create a DRAFT pull request.
draft?: boolean;
// Optional logger to set
logger?: Logger;
// Optional number of files per commit
filesPerCommit?: number;
}
/**
* GitHub data needed for creating a PR
*/
export interface CreatePullRequest {
// the owner of the target fork repository
upstreamOwner: string;
// the name of the target fork repository
upstreamRepo: string;
// The message of any commits made.
message: string;
// The description of the pull request.
description: string;
// The title of the pull request
title: string;
// the name of the branch to push changes to.
branch: string;
// Whether or not to force branch reference updates.
force: boolean;
// Primary upstream branch to open PRs against.
primary: string;
// Whether or not maintainers can modify the PR.
maintainersCanModify: boolean;
// Optional number of files per commit
filesPerCommit?: number;
}
/**
* The user options for creating GitHub PR review comment
*/
export interface CreateReviewCommentUserOptions {
// the owner of the target fork repository
owner: string;
// the name of the target fork repository
repo: string;
// The pull request number
pullNumber: number;
// The number of files to return per pull request list files query. Used when getting data on the remote PR's files.
pageSize?: number;
// Optional logger to set
logger?: Logger;
}
/**
* The user options for creating GitHub PR review comment
*/
export interface CreateReviewComment {
// the owner of the target fork repository
owner: string;
// the name of the target fork repository
repo: string;
// The pull request number
pullNumber: number;
// The number of files to return per pull request list files query. Used when getting data on the remote PR's files.
pageSize: number;
}
export class PatchSyntaxError extends Error {
constructor(message: string) {
super(message);
this.name = 'PatchSyntaxError';
}
}
/**
* The file content of the original content and the patched content
*/
export interface FileDiffContent {
readonly oldContent: string;
readonly newContent: string;
}
export interface Hunk {
readonly oldStart: number;
readonly oldEnd: number;
readonly newStart: number;
readonly newEnd: number;
readonly newContent: string[];
readonly previousLine?: string;
readonly nextLine?: string;
}
interface LogFn {
/* eslint-disable @typescript-eslint/no-explicit-any */
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
(msg: string, ...args: any[]): void;
/* eslint-enable @typescript-eslint/no-explicit-any */
}
export interface Logger {
error: LogFn;
warn: LogFn;
info: LogFn;
debug: LogFn;
trace: LogFn;
}
export interface UserData {
name: string;
email: string;
}
export interface CommitData {
message: string;
tree: string;
parents: string[];
author?: UserData;
committer?: UserData;
}
export interface CommitSigner {
generateSignature(commit: CommitData): Promise<string>;
}