Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(gitops): wrong jsonapi annotations for new format of commit structs (#4634)

Liu Ji7dcc0e84cebc
diff --git a/backend/plugin/vcs/vcs.go b/backend/plugin/vcs/vcs.go
index 4fe3e26af9..fa7ccfea27 100644
--- a/backend/plugin/vcs/vcs.go
+++ b/backend/plugin/vcs/vcs.go
@@ -44,15 +44,15 @@ type OAuthToken struct {
// Commit records the commit data.
type Commit struct {
- ID string
- Title string
- Message string
- CreatedTs int64
- URL string
- AuthorName string
- AuthorEmail string
- AddedList []string
- ModifiedList []string
+ ID string `json:"id"`
+ Title string `json:"title"`
+ Message string `json:"message"`
+ CreatedTs int64 `json:"createdTs"`
+ URL string `json:"url"`
+ AuthorName string `json:"authorName"`
+ AuthorEmail string `json:"authorEmail"`
+ AddedList []string `json:"addedList"`
+ ModifiedList []string `json:"modifiedList"`
}
// FileCommit is the API message for a VCS file commit.
diff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vue
index 0f62fedad9..a92e87b18c 100644
--- a/frontend/src/components/Issue/IssueHighlightPanel.vue
+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue
@@ -52,21 +52,22 @@
`${vcsBranch}@${pushEvent.repositoryFullPath}`
}}</a>
- <i18n-t keypath="issue.commit-by-at" tag="span">
+ <i18n-t
+ v-if="commit && commit.id && commit.url"
+ keypath="issue.commit-by-at"
+ tag="span"
+ >
<template #id>
- <a
- :href="pushEvent.fileCommit.url"
- target="_blank"
- class="normal-link"
- >{{ pushEvent.fileCommit.id.substring(0, 7) }}:</a
+ <a :href="commit.url" target="_blank" class="normal-link"
+ >{{ commit.id.substring(0, 7) }}:</a
>
</template>
<template #title>
- <span class="text-main">{{ pushEvent.fileCommit.title }}</span>
+ <span class="text-main">{{ commit.title }}</span>
</template>
<template #author>{{ pushEvent.authorName }}</template>
<template #time>{{
- dayjs(pushEvent.fileCommit.createdTs * 1000).format("LLL")
+ dayjs(commit.createdTs * 1000).format("LLL")
}}</template>
</i18n-t>
</p>
@@ -92,6 +93,7 @@ import {
VCSPushEvent,
} from "@/types";
import { useExtraIssueLogic, useIssueLogic } from "./logic";
+import { head } from "lodash-es";
interface LocalState {
editing: boolean;
@@ -128,6 +130,13 @@ const pushEvent = computed((): VCSPushEvent | undefined => {
return undefined;
});
+const commit = computed(() => {
+ // Use commits[0] for new format
+ // Use fileCommit for legacy data (if possible)
+ // Use undefined otherwise
+ return head(pushEvent.value?.commits) ?? pushEvent.value?.fileCommit;
+});
+
const vcsBranch = computed((): string => {
if (pushEvent.value) {
return pushEvent.value.ref.replace(/^refs\/heads\//g, "");
diff --git a/frontend/src/types/vcs.ts b/frontend/src/types/vcs.ts
index f939ec00c4..6755906bdd 100644
--- a/frontend/src/types/vcs.ts
+++ b/frontend/src/types/vcs.ts
@@ -53,6 +53,18 @@ export type VCSFileCommit = {
added: string;
};
+export type VCSCommit = {
+ id: string;
+ title: string;
+ message: string;
+ createdTs: number;
+ url: string;
+ authorName: string;
+ authorEmail: string;
+ addedList: string[];
+ modifiedList: string[];
+};
+
export type VCSPushEvent = {
vcsType: VCSType;
ref: string;
@@ -61,6 +73,7 @@ export type VCSPushEvent = {
repositoryFullPath: string;
authorName: string;
fileCommit: VCSFileCommit;
+ commits: VCSCommit[];
};
export function isValidVCSApplicationIdOrSecret(