Create getPatchCommitSuffix helper to help the patch list to filter commits

Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
Erik Engervall
2021-04-29 15:30:35 +02:00
parent 8d0e7f0adb
commit 34a5d56d80
4 changed files with 33 additions and 3 deletions
@@ -401,6 +401,7 @@ export class GitReleaseApiClient implements GitReleaseApi {
selectedPatchCommit,
mergeTree,
releaseBranchSha,
messageSuffix,
}) => {
const { octokit } = await this.getOctokit();
const { data: cherryPickCommit } = await octokit.git.createCommit({
@@ -408,7 +409,7 @@ export class GitReleaseApiClient implements GitReleaseApi {
repo,
message: `[patch ${bumpedTag}] ${selectedPatchCommit.commit.message}
${selectedPatchCommit.sha}`,
${messageSuffix}`,
tree: mergeTree,
parents: [releaseBranchSha],
});
@@ -757,6 +758,7 @@ export interface GitReleaseApi {
>;
mergeTree: string;
releaseBranchSha: string;
messageSuffix: string;
} & OwnerRepo,
) => Promise<{
message: string;
@@ -42,6 +42,7 @@ import { CalverTagParts } from '../../helpers/tagParts/getCalverTagParts';
import { CenteredCircularProgress } from '../../components/CenteredCircularProgress';
import { ComponentConfigPatch } from '../../types/types';
import { Differ } from '../../components/Differ';
import { getPatchCommitSuffix } from './helpers/getPatchCommitSuffix';
import { gitReleaseManagerApiRef } from '../../api/serviceApiRef';
import { GitReleaseManagerError } from '../../errors/GitReleaseManagerError';
import { ResponseStepDialog } from '../../components/ResponseStepDialog/ResponseStepDialog';
@@ -159,7 +160,11 @@ export const PatchBody = ({
const commitExistsOnReleaseBranch = !!gitDataResponse.value?.recentCommitsOnReleaseBranch.find(
releaseBranchCommit =>
releaseBranchCommit.sha === commit.sha ||
releaseBranchCommit.commit.message.includes(commit.sha), // The selected patch commit's sha is included in the commit message
// The selected patch commit's sha is included in the commit message,
// which means it's part of a previous patch
releaseBranchCommit.commit.message.includes(
getPatchCommitSuffix({ commitSha: commit.sha }),
),
);
const hasNoParent = !commit.firstParentSha;
@@ -0,0 +1,19 @@
/*
* Copyright 2021 Spotify AB
*
* 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
*
* http://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.
*/
export const getPatchCommitSuffix = ({ commitSha }: { commitSha: string }) => {
return `[Backstage patch ${commitSha}]`;
};
@@ -24,11 +24,12 @@ import {
} from '../../../api/GitReleaseApiClient';
import { CalverTagParts } from '../../../helpers/tagParts/getCalverTagParts';
import { ComponentConfigPatch, CardHook } from '../../../types/types';
import { getPatchCommitSuffix } from '../helpers/getPatchCommitSuffix';
import { gitReleaseManagerApiRef } from '../../../api/serviceApiRef';
import { Project } from '../../../contexts/ProjectContext';
import { SemverTagParts } from '../../../helpers/tagParts/getSemverTagParts';
import { useResponseSteps } from '../../../hooks/useResponseSteps';
import { TAG_OBJECT_MESSAGE } from '../../../constants/constants';
import { useResponseSteps } from '../../../hooks/useResponseSteps';
import { useUserContext } from '../../../contexts/UserContext';
interface Patch {
@@ -190,6 +191,9 @@ export function usePatch({
mergeTree: mergeRes.value.commit.tree.sha,
releaseBranchSha,
selectedPatchCommit: releaseBranchRes.value.selectedPatchCommit,
messageSuffix: getPatchCommitSuffix({
commitSha: releaseBranchRes.value.selectedPatchCommit.sha,
}),
})
.catch(asyncCatcher);