From 61e92b6c4bbf0a9c76e2c8d9fa3d27abeb337b95 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 20 Jun 2023 18:40:43 +0200 Subject: [PATCH 1/4] Handle Applications created by revision from CLI Signed-off-by: Francesco Torchia --- pkg/epinio/detail/applications.vue | 2 ++ shell/components/form/GitPicker.vue | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pkg/epinio/detail/applications.vue b/pkg/epinio/detail/applications.vue index 1afe674452..213b26b3aa 100644 --- a/pkg/epinio/detail/applications.vue +++ b/pkg/epinio/detail/applications.vue @@ -125,9 +125,11 @@ export default Vue.extend({ async fetchCommits() { const { usernameOrOrg, repo, branch } = this.value.appSource.git; + if (branch?.name) { this.gitDeployment.commits = await this.$store.dispatch(`${ this.gitType }/fetchCommits`, { username: usernameOrOrg, repo, branch }); + } }, formatDate(date: string, from: boolean) { day.extend(relativeTime); diff --git a/shell/components/form/GitPicker.vue b/shell/components/form/GitPicker.vue index 66dd446ac3..32ba4f7bbd 100644 --- a/shell/components/form/GitPicker.vue +++ b/shell/components/form/GitPicker.vue @@ -185,10 +185,12 @@ export default Vue.extend({ }) .then(() => { if (this.branches.length && !this.hasError.branch) { + if (branch?.name) { this.selectedBranch = branch; return this.fetchCommits(); } + } }); const selectedCommit = this.commits.find((c: commit) => { From 7d119e9a470feec485e0ad1a4f3b272b1ef2df47 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 20 Jun 2023 18:43:06 +0200 Subject: [PATCH 2/4] Clean up code Signed-off-by: Francesco Torchia --- pkg/epinio/detail/applications.vue | 30 +++++++++++++++-------------- shell/components/form/GitPicker.vue | 18 ++++------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/pkg/epinio/detail/applications.vue b/pkg/epinio/detail/applications.vue index 213b26b3aa..1eba3c741d 100644 --- a/pkg/epinio/detail/applications.vue +++ b/pkg/epinio/detail/applications.vue @@ -49,12 +49,14 @@ export default Vue.extend({ required: true }, }, - fetch() { + async fetch() { this.$store.dispatch(`epinio/findAll`, { type: EPINIO_TYPES.SERVICE_INSTANCE }); this.$store.dispatch(`epinio/findAll`, { type: EPINIO_TYPES.CONFIGURATION }); if (this.value.appSource.git) { - this.fetchRepoDetails(); + await this.fetchRepoDetails(); + + this.setCommitDetails(); } }, data() { @@ -111,26 +113,26 @@ export default Vue.extend({ this.gitSource = GitUtils[this.gitType].normalize.repo(res); - const commit = this.value.appSourceInfo?.details.filter((ele: { label: string; }) => ele.label === 'Revision')[0]?.value; - - if (commit) { - this.gitDeployment.deployedCommit = { - short: commit?.slice(0, 7), - long: commit - }; - } - await this.fetchCommits(); }, async fetchCommits() { const { usernameOrOrg, repo, branch } = this.value.appSource.git; if (branch?.name) { - this.gitDeployment.commits = await this.$store.dispatch(`${ this.gitType }/fetchCommits`, { - username: usernameOrOrg, repo, branch - }); + this.gitDeployment.commits = await this.$store.dispatch(`${ this.gitType }/fetchCommits`, { + username: usernameOrOrg, repo, branch + }); } }, + setCommitDetails() { + const { commit } = this.value.appSource.git; + const selectedCommit = this.preparedCommits.find((c: { commitId?: string }) => c.commitId === commit) || this.orderedCommits[0]; + + this.gitDeployment.deployedCommit = { + short: selectedCommit?.commitId?.slice(0, 7), + long: selectedCommit.commitId + }; + }, formatDate(date: string, from: boolean) { day.extend(relativeTime); diff --git a/shell/components/form/GitPicker.vue b/shell/components/form/GitPicker.vue index 32ba4f7bbd..4584575eb0 100644 --- a/shell/components/form/GitPicker.vue +++ b/shell/components/form/GitPicker.vue @@ -186,24 +186,14 @@ export default Vue.extend({ .then(() => { if (this.branches.length && !this.hasError.branch) { if (branch?.name) { - this.selectedBranch = branch; + this.selectedBranch = branch; - return this.fetchCommits(); - } + return this.fetchCommits(); + } } }); - const selectedCommit = this.commits.find((c: commit) => { - // Github has sha's - // Gitlab has id's as sha's - const sha = c.sha || c.id; - - return sha === commit.sha; - }); - - if (selectedCommit) { - this.final(selectedCommit.sha || selectedCommit.id); - } + this.final(commit.sha); } }, From 2f19d55e2722a7855f5f5d058e828a3465e0846b Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Wed, 21 Jun 2023 12:08:54 +0100 Subject: [PATCH 3/4] Hide app detail git commit tabs if there's no commits to show --- pkg/epinio/detail/applications.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/epinio/detail/applications.vue b/pkg/epinio/detail/applications.vue index 1eba3c741d..4f8c21818e 100644 --- a/pkg/epinio/detail/applications.vue +++ b/pkg/epinio/detail/applications.vue @@ -423,7 +423,7 @@ export default Vue.extend({ Date: Wed, 21 Jun 2023 12:10:50 +0100 Subject: [PATCH 4/4] Bring back validation of selected commit - this may have been deleted since the app was previously deployed --- shell/components/form/GitPicker.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/shell/components/form/GitPicker.vue b/shell/components/form/GitPicker.vue index 4584575eb0..6da0860848 100644 --- a/shell/components/form/GitPicker.vue +++ b/shell/components/form/GitPicker.vue @@ -193,7 +193,17 @@ export default Vue.extend({ } }); - this.final(commit.sha); + const selectedCommit = this.commits?.find((c: commit) => { + // Github has sha's + // Gitlab has id's as sha's + const sha = c.sha || c.id; + + return sha === commit.sha; + }); + + if (selectedCommit) { + this.final(selectedCommit.sha || selectedCommit.id); + } } },