diff --git a/plugins/github-release-manager/src/GitHubReleaseManager.tsx b/plugins/github-release-manager/src/GitHubReleaseManager.tsx
index 3f7887ad53..3876d2b3fc 100644
--- a/plugins/github-release-manager/src/GitHubReleaseManager.tsx
+++ b/plugins/github-release-manager/src/GitHubReleaseManager.tsx
@@ -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 {gitHubBatchInfo.error.message};
}
@@ -140,6 +147,15 @@ function Cards({
);
}
+ if (!versioningStrategyMatches) {
+ return (
+
+ Versioning mismatch, expected {project.versioningStrategy} version, got{' '}
+ {gitHubBatchInfo.value?.latestRelease?.tag_name}
+
+ );
+ }
+
return (
diff --git a/plugins/github-release-manager/src/api/PluginApiClient.ts b/plugins/github-release-manager/src/api/PluginApiClient.ts
index c0a6476b2b..24310ef688 100644
--- a/plugins/github-release-manager/src/api/PluginApiClient.ts
+++ b/plugins/github-release-manager/src/api/PluginApiClient.ts
@@ -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,
},
};
}
diff --git a/plugins/github-release-manager/src/cards/patchRc/sideEffects/patch.ts b/plugins/github-release-manager/src/cards/patchRc/sideEffects/patch.ts
index de24b5b142..7bb0d5e6f0 100644
--- a/plugins/github-release-manager/src/cards/patchRc/sideEffects/patch.ts
+++ b/plugins/github-release-manager/src/cards/patchRc/sideEffects/patch.ts
@@ -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}`,
diff --git a/plugins/github-release-manager/src/helpers/tagParts/getTagParts.ts b/plugins/github-release-manager/src/helpers/tagParts/getTagParts.ts
index ff42779d99..a3f8665554 100644
--- a/plugins/github-release-manager/src/helpers/tagParts/getTagParts.ts
+++ b/plugins/github-release-manager/src/helpers/tagParts/getTagParts.ts
@@ -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,
diff --git a/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts b/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts
new file mode 100644
index 0000000000..91f4501585
--- /dev/null
+++ b/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts
@@ -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,
+ };
+};
diff --git a/plugins/github-release-manager/src/types/types.ts b/plugins/github-release-manager/src/types/types.ts
index be0fa6169b..04f53fd80a 100644
--- a/plugins/github-release-manager/src/types/types.ts
+++ b/plugins/github-release-manager/src/types/types.ts
@@ -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 {
successCb?: (args: Args) => Promise | void;
omit?: boolean;