Flatten & normalize Api. forceBranchHeadToTempCommit & replaceTempCommit -> updateRef
Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
@@ -56,12 +56,11 @@ describe('GitReleaseApiClient', () => {
|
||||
"host": "github.com",
|
||||
"patch": Object {
|
||||
"createCherryPickCommit": [Function],
|
||||
"forceBranchHeadToTempCommit": [Function],
|
||||
"merge": [Function],
|
||||
"replaceTempCommit": [Function],
|
||||
"updateRelease": [Function],
|
||||
},
|
||||
"promoteRelease": [Function],
|
||||
"updateRef": [Function],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
@@ -214,30 +214,26 @@ export class GitReleaseApiClient implements GitReleaseApi {
|
||||
};
|
||||
};
|
||||
|
||||
getBranch: GitReleaseApi['getBranch'] = async ({
|
||||
owner,
|
||||
repo,
|
||||
branchName,
|
||||
}) => {
|
||||
getBranch: GitReleaseApi['getBranch'] = async ({ owner, repo, branch }) => {
|
||||
const { octokit } = await this.getOctokit();
|
||||
|
||||
const { data: branch } = await octokit.repos.getBranch({
|
||||
const { data: branchData } = await octokit.repos.getBranch({
|
||||
owner,
|
||||
repo,
|
||||
branch: branchName,
|
||||
branch,
|
||||
...DISABLE_CACHE,
|
||||
});
|
||||
|
||||
return {
|
||||
name: branch.name,
|
||||
name: branchData.name,
|
||||
links: {
|
||||
html: branch._links.html,
|
||||
html: branchData._links.html,
|
||||
},
|
||||
commit: {
|
||||
sha: branch.commit.sha,
|
||||
sha: branchData.commit.sha,
|
||||
commit: {
|
||||
tree: {
|
||||
sha: branch.commit.commit.tree.sha,
|
||||
sha: branchData.commit.commit.tree.sha,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -309,7 +305,7 @@ export class GitReleaseApiClient implements GitReleaseApi {
|
||||
owner,
|
||||
repo,
|
||||
tag,
|
||||
objectSha,
|
||||
object,
|
||||
taggerName,
|
||||
taggerEmail,
|
||||
message,
|
||||
@@ -320,7 +316,7 @@ export class GitReleaseApiClient implements GitReleaseApi {
|
||||
repo,
|
||||
message,
|
||||
tag,
|
||||
object: objectSha,
|
||||
object,
|
||||
type: 'commit',
|
||||
tagger: {
|
||||
date: new Date().toISOString(),
|
||||
@@ -357,18 +353,31 @@ export class GitReleaseApiClient implements GitReleaseApi {
|
||||
};
|
||||
};
|
||||
|
||||
patch: GitReleaseApi['patch'] = {
|
||||
forceBranchHeadToTempCommit: async ({ owner, repo, ref, sha }) => {
|
||||
const { octokit } = await this.getOctokit();
|
||||
await octokit.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref,
|
||||
sha,
|
||||
force: true,
|
||||
});
|
||||
},
|
||||
updateRef: GitReleaseApi['updateRef'] = async ({
|
||||
owner,
|
||||
repo,
|
||||
ref,
|
||||
sha,
|
||||
force,
|
||||
}) => {
|
||||
const { octokit } = await this.getOctokit();
|
||||
const { data: updatedRef } = await octokit.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref,
|
||||
sha,
|
||||
force,
|
||||
});
|
||||
|
||||
return {
|
||||
ref: updatedRef.ref,
|
||||
object: {
|
||||
sha: updatedRef.object.sha,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
patch: GitReleaseApi['patch'] = {
|
||||
merge: async ({ owner, repo, base, head }) => {
|
||||
const { octokit } = await this.getOctokit();
|
||||
const { data: merge } = await octokit.repos.merge({
|
||||
@@ -415,29 +424,6 @@ ${messageSuffix}`,
|
||||
};
|
||||
},
|
||||
|
||||
replaceTempCommit: async ({
|
||||
owner,
|
||||
repo,
|
||||
releaseBranchName,
|
||||
cherryPickCommit,
|
||||
}) => {
|
||||
const { octokit } = await this.getOctokit();
|
||||
const { data: updatedReference } = await octokit.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `heads/${releaseBranchName}`,
|
||||
sha: cherryPickCommit.sha,
|
||||
force: true,
|
||||
});
|
||||
|
||||
return {
|
||||
ref: updatedReference.ref,
|
||||
object: {
|
||||
sha: updatedReference.object.sha,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
updateRelease: async ({
|
||||
owner,
|
||||
repo,
|
||||
@@ -627,7 +613,7 @@ export interface GitReleaseApi {
|
||||
|
||||
getBranch: (
|
||||
args: {
|
||||
branchName: string;
|
||||
branch: string;
|
||||
} & OwnerRepo,
|
||||
) => Promise<{
|
||||
name: string;
|
||||
@@ -682,7 +668,7 @@ export interface GitReleaseApi {
|
||||
tag: string;
|
||||
taggerEmail?: string;
|
||||
message: string;
|
||||
objectSha: string;
|
||||
object: string;
|
||||
taggerName: string;
|
||||
} & OwnerRepo,
|
||||
) => Promise<{
|
||||
@@ -701,14 +687,20 @@ export interface GitReleaseApi {
|
||||
sha: string;
|
||||
}>;
|
||||
|
||||
patch: {
|
||||
forceBranchHeadToTempCommit: (
|
||||
args: {
|
||||
sha: string;
|
||||
ref: string;
|
||||
} & OwnerRepo,
|
||||
) => Promise<void>;
|
||||
updateRef: (
|
||||
args: {
|
||||
sha: string;
|
||||
ref: string;
|
||||
force: boolean;
|
||||
} & OwnerRepo,
|
||||
) => Promise<{
|
||||
ref: string;
|
||||
object: {
|
||||
sha: string;
|
||||
};
|
||||
}>;
|
||||
|
||||
patch: {
|
||||
merge: (
|
||||
args: {
|
||||
base: string;
|
||||
@@ -739,20 +731,6 @@ export interface GitReleaseApi {
|
||||
sha: string;
|
||||
}>;
|
||||
|
||||
replaceTempCommit: (
|
||||
args: {
|
||||
releaseBranchName: string;
|
||||
cherryPickCommit: UnboxReturnedPromise<
|
||||
GitReleaseApi['patch']['createCherryPickCommit']
|
||||
>;
|
||||
} & OwnerRepo,
|
||||
) => Promise<{
|
||||
ref: string;
|
||||
object: {
|
||||
sha: string;
|
||||
};
|
||||
}>;
|
||||
|
||||
updateRelease: (
|
||||
args: {
|
||||
bumpedTag: string;
|
||||
@@ -847,16 +825,10 @@ export type GetComparisonResult = UnboxReturnedPromise<
|
||||
export type CreateReleaseResult = UnboxReturnedPromise<
|
||||
GitReleaseApi['createRelease']
|
||||
>;
|
||||
export type ForceBranchHeadToTempCommitResult = UnboxReturnedPromise<
|
||||
GitReleaseApi['patch']['forceBranchHeadToTempCommit']
|
||||
>;
|
||||
export type MergeResult = UnboxReturnedPromise<GitReleaseApi['patch']['merge']>;
|
||||
export type CreateCherryPickCommitResult = UnboxReturnedPromise<
|
||||
GitReleaseApi['patch']['createCherryPickCommit']
|
||||
>;
|
||||
export type ReplaceTempCommitResult = UnboxReturnedPromise<
|
||||
GitReleaseApi['patch']['replaceTempCommit']
|
||||
>;
|
||||
export type CreateTagObjectResult = UnboxReturnedPromise<
|
||||
GitReleaseApi['createTagObject']
|
||||
>;
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ export function useCreateReleaseCandidate({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
tag: releaseCandidateGitInfo.rcReleaseTag,
|
||||
objectSha: releaseBranchRes.value.objectSha,
|
||||
object: releaseBranchRes.value.objectSha,
|
||||
taggerName: user.username,
|
||||
taggerEmail: user.email,
|
||||
message: TAG_OBJECT_MESSAGE,
|
||||
|
||||
@@ -99,7 +99,7 @@ describe('patch', () => {
|
||||
"secondaryMessage": "with message \\"mock_cherrypick_message\\"",
|
||||
},
|
||||
Object {
|
||||
"message": "Updated reference \\"mock_reference_ref\\"",
|
||||
"message": "Updated reference \\"mock_update_ref_ref\\"",
|
||||
},
|
||||
Object {
|
||||
"message": "Created new tag object",
|
||||
|
||||
@@ -71,7 +71,7 @@ export function usePatch({
|
||||
.getBranch({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
branchName: releaseBranchName,
|
||||
branch: releaseBranchName,
|
||||
})
|
||||
.catch(asyncCatcher);
|
||||
|
||||
@@ -127,12 +127,13 @@ export function usePatch({
|
||||
abortIfError(tempCommitRes.error);
|
||||
if (!tempCommitRes.value) return undefined;
|
||||
|
||||
await pluginApiClient.patch
|
||||
.forceBranchHeadToTempCommit({
|
||||
await pluginApiClient
|
||||
.updateRef({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
sha: tempCommitRes.value.sha,
|
||||
ref: `heads/${releaseBranchName}`,
|
||||
force: true,
|
||||
})
|
||||
.catch(asyncCatcher);
|
||||
|
||||
@@ -216,12 +217,13 @@ export function usePatch({
|
||||
abortIfError(cherryPickRes.error);
|
||||
if (!cherryPickRes.value) return undefined;
|
||||
|
||||
const updatedReference = await pluginApiClient.patch
|
||||
.replaceTempCommit({
|
||||
const updatedReference = await pluginApiClient
|
||||
.updateRef({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
cherryPickCommit: cherryPickRes.value,
|
||||
releaseBranchName,
|
||||
ref: `heads/${releaseBranchName}`,
|
||||
sha: cherryPickRes.value.sha,
|
||||
force: true,
|
||||
})
|
||||
.catch(asyncCatcher);
|
||||
|
||||
@@ -247,7 +249,7 @@ export function usePatch({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
tag: bumpedTag,
|
||||
objectSha: updatedRefRes.value.object.sha,
|
||||
object: updatedRefRes.value.object.sha,
|
||||
message: TAG_OBJECT_MESSAGE,
|
||||
taggerName: user.username,
|
||||
taggerEmail: user.email,
|
||||
|
||||
@@ -82,7 +82,7 @@ export function usePromoteRc({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
tag: releaseVersion,
|
||||
objectSha: latestReleaseBranchCommitSha.value.sha,
|
||||
object: latestReleaseBranchCommitSha.value.sha,
|
||||
taggerName: user.username,
|
||||
taggerEmail: user.email,
|
||||
message: TAG_OBJECT_MESSAGE,
|
||||
|
||||
@@ -53,7 +53,7 @@ export const useGetGitBatchInfo = ({
|
||||
const releaseBranch = await pluginApiClient.getBranch({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
branchName: latestRelease.targetCommitish,
|
||||
branch: latestRelease.targetCommitish,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -246,14 +246,19 @@ export const mockApiClient: GitReleaseApi = {
|
||||
sha: 'mock_commit_sha',
|
||||
})),
|
||||
|
||||
updateRef: jest.fn(async () => ({
|
||||
ref: 'mock_update_ref_ref',
|
||||
object: {
|
||||
sha: 'mock_update_ref_object_sha',
|
||||
},
|
||||
})),
|
||||
|
||||
patch: {
|
||||
createCherryPickCommit: jest.fn(async () => ({
|
||||
message: 'mock_cherrypick_message',
|
||||
sha: 'mock_cherrypick_sha',
|
||||
})),
|
||||
|
||||
forceBranchHeadToTempCommit: jest.fn(async () => undefined),
|
||||
|
||||
merge: jest.fn(async () => ({
|
||||
htmlUrl: 'mock_merge_html_url',
|
||||
commit: {
|
||||
@@ -264,13 +269,6 @@ export const mockApiClient: GitReleaseApi = {
|
||||
},
|
||||
})),
|
||||
|
||||
replaceTempCommit: jest.fn(async () => ({
|
||||
ref: 'mock_reference_ref',
|
||||
object: {
|
||||
sha: 'mock_reference_object_sha',
|
||||
},
|
||||
})),
|
||||
|
||||
updateRelease: jest.fn(async () => ({
|
||||
name: 'mock_update_release_name',
|
||||
tagName: 'mock_update_release_tag_name',
|
||||
|
||||
Reference in New Issue
Block a user