Skip to content

Commit

Permalink
feat: allow to filter reports by scmid
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Vernin <[email protected]>
  • Loading branch information
olblak committed Nov 6, 2024
1 parent fd59569 commit 33329c3
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 3 deletions.
125 changes: 125 additions & 0 deletions src/components/scm/_filter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<template>
<v-container
class="py-8 px-6"
fluid
>
<v-form v-model="filterForm" @submit.prevent="applyFilter">
<!-- Repository Dropdown -->
<v-select
label="Git Repository"
:items="repositories"
:rules="[v => !!v || 'Git repository is required']"
v-model="repository"
></v-select>

<v-select
label="Git Branch"
:items="branches"
:rules="[v => !!v || 'Git branch is required']"
v-model="branch"
></v-select>

<!-- Filter repository-->
<!--<v-btn type="submit" color="primary" :disabled="!filterForm">Filter</v-btn>-->
</v-form>

</v-container>
</template>

<script>
export default {
name: 'PipelineSCMS',
props: {
scmid: {},
},
data: () => ({
isLoading: true,
filterForm: false,
scms: [],
repository: "",
repositories : [],
branches: [],
branch : "",
}),
beforeUnmount() {
this.cancelAutoUpdate();
},
computed: {
},
methods: {
async getSCMSData() {
const token = await this.$auth0.getAccessTokenSilently();
const response = await fetch('/api/pipeline/scms', {
headers: {
Authorization: `Bearer ${token}`
}
});
const data = await response.json();
this.isLoading = false
this.scms = data.scms
this.repositories = this.scms.map(scm => scm.URL)
if (this.repositories.length > 0) {
this.repository = this.repositories[0]
}
},
getScmID(url, branch) {
return this.scms.find(scm => scm.URL === url && scm.Branch === branch).ID
},
applyFilter() {
var scmid = this.getScmID(this.repository, this.branch)
this.$emit('update-scmid', scmid)
},
cancelAutoUpdate() {
clearInterval(this.timer);
},
},
watch: {
isLoading (val) {
val && setTimeout(() => {
this.isLoading = false
}, 3000)
},
repository (val) {
var b = []
for (var i =0 ; i < this.scms.length; i++) {
if (this.scms[i].URL == val) {
if (this.scms[i].Branch == "main") {
this.branch = "main"
}
if (this.scms[i].Branch == "master" && this.branch == "" ){
this.branch = "master"
}
b.push(this.scms[i].Branch)
}
}
this.branches = b
this.applyFilter()
},
branch () {
this.applyFilter()
},
},
async created() {
try {
this.getSCMSData()
} catch (error) {
console.log(error);
}
},
}
</script>
52 changes: 52 additions & 0 deletions src/components/scm/_summary.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<v-card>
<v-card-title
class="text-center"
>
<h2>{{ sanitizeURL(data.URL) }} - {{ data.Branch }}</h2>
</v-card-title>
</v-card>
</template>

<script>
export default {
name: "SCMSummary",
props: {
scmid: {},
},
data: () => ({
data: {},
}),
methods: {
sanitizeURL: function(url) {
if (url === undefined) {
return "";
}
url = url.replace(/https?:\/\//, '');
url = url.replace(/http?:\/\//, '');
url = url.replace(/\/$/, '');
url = url.replace(/\.git$/, '');
return url;
},
},
async created() {
try {
const token = await this.$auth0.getAccessTokenSilently();
const response = await fetch(`/api/pipeline/scms?scmid=${this.scmid}`, {
headers: {
Authorization: `Bearer ${token}`
}
});
const data = await response.json();
this.data = data.scms[0];
} catch (error) {
console.error(error);
}
},
}
</script>
17 changes: 14 additions & 3 deletions src/views/pipeline/ReportsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
</v-col>
</v-row>
</v-container>
<PipelineReports/>
<PipelineSCMFilter :scmid="scmid" @update-scmid="updateSCMID"/>
<PipelineReports :scmid="scmid" @update-scmid="updateSCMID"/>
</v-main>

<ReleaseFooter/>
Expand All @@ -33,13 +34,16 @@ import SideNavigation from '../../components/SideNavigation.vue';
import HeadNavigation from '../../components/HeadNavigation.vue';
import PipelineReports from '../../components/pipeline/reports.vue';
import PipelineSCMSFilter from '../../components/scm/_filter.vue';
export default {
name: 'PipelineReportsView',
components: {
ReleaseFooter,
SideNavigation,
HeadNavigation,
PipelineReports,
PipelineSCMFilter: PipelineSCMSFilter,
},
data: () => ({
links:[
Expand All @@ -48,7 +52,14 @@ export default {
to: "https://www.updatecli.io",
icon: "mdi-arrow-right-circle",
},
]
})
],
scmid: "",
}),
methods: {
updateSCMID(scmid) {
this.scmid = scmid;
},
}
}
</script>

0 comments on commit 33329c3

Please sign in to comment.