@teleporthq/teleport-github-gateway 0.19.23 → 0.20.7
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/cjs/github-instance.d.ts +328 -1
- package/dist/cjs/github-instance.js +87 -24
- package/dist/cjs/github-instance.js.map +1 -1
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +8 -0
- package/dist/esm/github-instance.d.ts +328 -1
- package/dist/esm/github-instance.js +87 -24
- package/dist/esm/github-instance.js.map +1 -1
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +8 -0
- package/package.json +3 -3
- package/src/github-instance.ts +36 -1
- package/src/index.ts +7 -0
- package/src/types.ts +9 -0
package/src/github-instance.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
CreateBranchMeta,
|
|
23
23
|
RepositoryMergeMeta,
|
|
24
24
|
RemoveBranchMeta,
|
|
25
|
+
CompareBranchesMeta,
|
|
25
26
|
} from './types'
|
|
26
27
|
|
|
27
28
|
export default class GithubInstance {
|
|
@@ -168,6 +169,34 @@ export default class GithubInstance {
|
|
|
168
169
|
return removeResult.status
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
public async compareBranches(meta: CompareBranchesMeta) {
|
|
173
|
+
const { owner, repo, base, head } = meta
|
|
174
|
+
const compare = await this.octokit.rest.repos.compareCommits({ owner, repo, base, head })
|
|
175
|
+
|
|
176
|
+
const fileContentPromises = compare.data.files?.map(async (file) => {
|
|
177
|
+
try {
|
|
178
|
+
const { data } = await this.octokit.rest.repos.getContent({
|
|
179
|
+
repo,
|
|
180
|
+
owner,
|
|
181
|
+
ref: head,
|
|
182
|
+
path: file.filename,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
const response = await fetch((data as { download_url: string }).download_url)
|
|
186
|
+
return response.text()
|
|
187
|
+
} catch (error) {
|
|
188
|
+
return Promise.resolve(null)
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const fileContents = await Promise.all(fileContentPromises)
|
|
193
|
+
compare.data.files.forEach((file, index: number) => {
|
|
194
|
+
Object.assign(file, { content: fileContents[index] })
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
return compare.data
|
|
198
|
+
}
|
|
199
|
+
|
|
171
200
|
public async getCommitData(meta: RepositoryCommitMeta) {
|
|
172
201
|
const { owner, repo, ref } = meta
|
|
173
202
|
const repository = await this.octokit.rest.repos.get({ owner, repo })
|
|
@@ -226,6 +255,7 @@ export default class GithubInstance {
|
|
|
226
255
|
branchName,
|
|
227
256
|
isPrivate,
|
|
228
257
|
files,
|
|
258
|
+
extraBranchParents = [],
|
|
229
259
|
repositoryIdentity,
|
|
230
260
|
commitMessage = DEFAULT_COMMIT_MESSAGE,
|
|
231
261
|
} = commitMeta
|
|
@@ -246,6 +276,11 @@ export default class GithubInstance {
|
|
|
246
276
|
|
|
247
277
|
// Step 2: Get branch commit SHA
|
|
248
278
|
const commitSHA = await this.getBranchHeadCommitSHA(owner, repo, branchName)
|
|
279
|
+
const extraParentsShaPromises = extraBranchParents.map((branch) =>
|
|
280
|
+
this.getBranchHeadCommitSHA(owner, repo, branch)
|
|
281
|
+
)
|
|
282
|
+
const extraSHAs = await Promise.all(extraParentsShaPromises)
|
|
283
|
+
const parents = [commitSHA, ...extraSHAs]
|
|
249
284
|
|
|
250
285
|
// Step 3: Get current tree SHA
|
|
251
286
|
const treeSHA = await this.getCommitTreeSHA(owner, repo, commitSHA)
|
|
@@ -260,8 +295,8 @@ export default class GithubInstance {
|
|
|
260
295
|
const newCommit = await this.octokit.rest.git.createCommit({
|
|
261
296
|
owner,
|
|
262
297
|
repo,
|
|
298
|
+
parents,
|
|
263
299
|
message: commitMessage,
|
|
264
|
-
parents: [commitSHA],
|
|
265
300
|
tree: newTreeSHA,
|
|
266
301
|
})
|
|
267
302
|
const newCommitSHA = newCommit.data.sha
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
CreateBranchMeta,
|
|
15
15
|
RepositoryMergeMeta,
|
|
16
16
|
RemoveBranchMeta,
|
|
17
|
+
CompareBranchesMeta,
|
|
17
18
|
} from './types'
|
|
18
19
|
|
|
19
20
|
export const createGithubGateway: GithubGatewayFactory = (auth: ServiceAuth = {}) => {
|
|
@@ -76,6 +77,11 @@ export const createGithubGateway: GithubGatewayFactory = (auth: ServiceAuth = {}
|
|
|
76
77
|
return githubInstance.getCommitData(meta)
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
const compare = async (meta: CompareBranchesMeta, authData: ServiceAuth) => {
|
|
81
|
+
authorizeGithubInstance(authData)
|
|
82
|
+
return githubInstance.compareBranches(meta)
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
const authorizeGithubInstance = (authData?: ServiceAuth): void => {
|
|
80
86
|
if (!authData) {
|
|
81
87
|
return
|
|
@@ -94,6 +100,7 @@ export const createGithubGateway: GithubGatewayFactory = (auth: ServiceAuth = {}
|
|
|
94
100
|
deleteRepositoryBranch,
|
|
95
101
|
commitFilesToRepo,
|
|
96
102
|
getCommitData,
|
|
103
|
+
compare,
|
|
97
104
|
authorizeGithubInstance,
|
|
98
105
|
}
|
|
99
106
|
}
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface GithubGateway {
|
|
|
15
15
|
deleteRepositoryBranch: (meta: RemoveBranchMeta, authData: ServiceAuth) => Promise<any>
|
|
16
16
|
getRepositoryBranches: (owner: string, repo: string, authData: ServiceAuth) => Promise<any>
|
|
17
17
|
getCommitData: (meta: RepositoryCommitMeta, authData: ServiceAuth) => Promise<any>
|
|
18
|
+
compare: (meta: CompareBranchesMeta, authData: ServiceAuth) => Promise<any>
|
|
18
19
|
authorizeGithubInstance: (authData?: ServiceAuth) => void
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -29,6 +30,7 @@ export interface GithubCommitMeta {
|
|
|
29
30
|
files: GithubFile[]
|
|
30
31
|
repositoryIdentity: RepositoryIdentity
|
|
31
32
|
branchName: string
|
|
33
|
+
extraBranchParents?: string[]
|
|
32
34
|
commitMessage?: string
|
|
33
35
|
isPrivate?: boolean
|
|
34
36
|
}
|
|
@@ -68,6 +70,13 @@ export interface RemoveBranchMeta {
|
|
|
68
70
|
branch: string
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
export interface CompareBranchesMeta {
|
|
74
|
+
repo: string
|
|
75
|
+
owner: string
|
|
76
|
+
base: string
|
|
77
|
+
head: string
|
|
78
|
+
}
|
|
79
|
+
|
|
71
80
|
export interface GithubFile {
|
|
72
81
|
content: string
|
|
73
82
|
name: string
|