Introduce useVersioningStrategyMatchesRepoTags to validate versioningStratefy match at an earlier stage
Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { Alert } from '@material-ui/lab';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
import { useAsync } from 'react-use';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useApi, ContentHeader, ErrorBoundary } from '@backstage/core';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { CreateRc } from './cards/createRc/CreateRc';
|
||||
import { getGitHubBatchInfo } from './sideEffects/getGitHubBatchInfo';
|
||||
@@ -41,6 +41,7 @@ import { isProjectValid } from './cards/projectForm/isProjectValid';
|
||||
import { InfoCardPlus } from './components/InfoCardPlus';
|
||||
import { RepoDetailsForm } from './cards/projectForm/RepoDetailsForm';
|
||||
import { CenteredCircularProgress } from './components/CenteredCircularProgress';
|
||||
import { useVersioningStrategyMatchesRepoTags } from './helpers/useVersioningStrategyMatchesRepoTags';
|
||||
|
||||
interface GitHubReleaseManagerProps {
|
||||
components?: {
|
||||
@@ -117,6 +118,12 @@ function Cards({
|
||||
[project, refetch],
|
||||
);
|
||||
|
||||
const { versioningStrategyMatches } = useVersioningStrategyMatchesRepoTags({
|
||||
latestReleaseTagName: gitHubBatchInfo.value?.latestRelease?.tag_name,
|
||||
project,
|
||||
repositoryName: gitHubBatchInfo.value?.repository.name,
|
||||
});
|
||||
|
||||
if (gitHubBatchInfo.error) {
|
||||
return <Alert severity="error">{gitHubBatchInfo.error.message}</Alert>;
|
||||
}
|
||||
@@ -140,6 +147,15 @@ function Cards({
|
||||
);
|
||||
}
|
||||
|
||||
if (!versioningStrategyMatches) {
|
||||
return (
|
||||
<Alert severity="error">
|
||||
Versioning mismatch, expected {project.versioningStrategy} version, got{' '}
|
||||
{gitHubBatchInfo.value?.latestRelease?.tag_name}
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ProjectContext.Provider value={project}>
|
||||
<ErrorBoundary>
|
||||
|
||||
@@ -304,7 +304,7 @@ export class PluginApiClient implements IPluginApiClient {
|
||||
const { octokit } = await this.getOctokit();
|
||||
|
||||
const { data: repository } = await octokit.repos.get({
|
||||
owner: owner,
|
||||
owner,
|
||||
repo,
|
||||
});
|
||||
|
||||
@@ -312,6 +312,7 @@ export class PluginApiClient implements IPluginApiClient {
|
||||
repository: {
|
||||
pushPermissions: repository.permissions?.push,
|
||||
defaultBranch: repository.default_branch,
|
||||
name: repository.name,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import {
|
||||
import { CalverTagParts } from '../../../helpers/tagParts/getCalverTagParts';
|
||||
import { GitHubReleaseManagerError } from '../../../errors/GitHubReleaseManagerError';
|
||||
import { PluginApiClient } from '../../../api/PluginApiClient';
|
||||
import { SemverTagParts } from '../../../helpers/tagParts/getSemverTagParts';
|
||||
import { Project } from '../../../contexts/ProjectContext';
|
||||
import { SemverTagParts } from '../../../helpers/tagParts/getSemverTagParts';
|
||||
|
||||
interface Patch {
|
||||
bumpedTag: string;
|
||||
@@ -181,15 +181,15 @@ export async function patch({
|
||||
/**
|
||||
* 9. Update release
|
||||
*/
|
||||
const {
|
||||
release: updatedRelease,
|
||||
} = await pluginApiClient.patch.updateRelease({
|
||||
...project,
|
||||
bumpedTag,
|
||||
latestRelease,
|
||||
selectedPatchCommit,
|
||||
tagParts,
|
||||
});
|
||||
const { release: updatedRelease } = await pluginApiClient.patch.updateRelease(
|
||||
{
|
||||
...project,
|
||||
bumpedTag,
|
||||
latestRelease,
|
||||
selectedPatchCommit,
|
||||
tagParts,
|
||||
},
|
||||
);
|
||||
responseSteps.push({
|
||||
message: `Updated release "${updatedRelease.name}"`,
|
||||
secondaryMessage: `with tag ${updatedRelease.tag_name}`,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { getCalverTagParts } from './getCalverTagParts';
|
||||
import { getSemverTagParts } from './getSemverTagParts';
|
||||
import { Project } from '../../types/types';
|
||||
import { Project } from '../../contexts/ProjectContext';
|
||||
|
||||
export function getTagParts({
|
||||
project,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { Project } from '../contexts/ProjectContext';
|
||||
import { getTagParts } from './tagParts/getTagParts';
|
||||
|
||||
export const useVersioningStrategyMatchesRepoTags = ({
|
||||
latestReleaseTagName,
|
||||
project,
|
||||
repositoryName,
|
||||
}: {
|
||||
latestReleaseTagName?: string;
|
||||
project: Project;
|
||||
repositoryName?: string;
|
||||
}) => {
|
||||
const [versioningStrategyMatches, setVersioningStrategyMatches] = useState(
|
||||
false,
|
||||
);
|
||||
useEffect(() => {
|
||||
setVersioningStrategyMatches(false);
|
||||
|
||||
if (latestReleaseTagName) {
|
||||
try {
|
||||
if (project.repo === repositoryName) {
|
||||
getTagParts({ project, tag: latestReleaseTagName });
|
||||
setVersioningStrategyMatches(true);
|
||||
}
|
||||
} catch (error) {
|
||||
setVersioningStrategyMatches(false);
|
||||
}
|
||||
}
|
||||
}, [latestReleaseTagName, project, repositoryName]);
|
||||
|
||||
return {
|
||||
versioningStrategyMatches,
|
||||
};
|
||||
};
|
||||
@@ -14,32 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// export interface Project {
|
||||
// /**
|
||||
// * Repository's owner (user or organisation)
|
||||
// *
|
||||
// * @example erikengervall
|
||||
// */
|
||||
// owner: string;
|
||||
|
||||
// /**
|
||||
// * Repository's name
|
||||
// *
|
||||
// * @example dockest
|
||||
// */
|
||||
// repo: string;
|
||||
|
||||
// /**
|
||||
// * Declares the versioning strategy of the project
|
||||
// *
|
||||
// * semver: `1.2.3` (major.minor.patch)
|
||||
// * calver: `2020.01.01_0` (YYYY.0M.0D_patch)
|
||||
// *
|
||||
// * Default: false
|
||||
// */
|
||||
// versioningStrategy: 'calver' | 'semver';
|
||||
// }
|
||||
|
||||
interface ComponentConfig<Args = void> {
|
||||
successCb?: (args: Args) => Promise<void> | void;
|
||||
omit?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user