Skip to content

Commit 84b245d

Browse files
committed
feat(ui): load branches
1 parent 5aa5fb4 commit 84b245d

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

web/src/components/TemplateForm.vue

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,47 @@
199199
:rules="isFieldRequired('repository') ? [v => !!v || $t('repository_required')] : []"
200200
outlined
201201
dense
202+
hide-details
202203
:required="isFieldRequired('repository')"
203204
:disabled="formSaving"
204205
v-if="needField('repository')"
205206
></v-autocomplete>
206207

208+
<div class="mb-3 text-right">
209+
210+
<a
211+
v-if="!item.git_branch && !setBranch"
212+
@click="setBranch = true"
213+
>Set branch</a>
214+
215+
</div>
216+
217+
<div v-if="item.git_branch || setBranch">
218+
<div v-if="branches != null">
219+
<v-autocomplete
220+
clearable
221+
:items="branches"
222+
v-model="item.git_branch"
223+
:label="fieldLabel('branch')"
224+
outlined
225+
dense
226+
:disabled="formSaving"
227+
:placeholder="$t('branch')"
228+
></v-autocomplete>
229+
</div>
230+
<div v-else>
231+
<v-text-field
232+
clearable
233+
v-model="item.git_branch"
234+
:label="fieldLabel('branch')"
235+
outlined
236+
dense
237+
:disabled="formSaving"
238+
:placeholder="$t('branch')"
239+
></v-text-field>
240+
</div>
241+
</div>
242+
207243
<v-autocomplete
208244
v-model="item.environment_id"
209245
:label="fieldLabel('environment')"
@@ -237,14 +273,6 @@
237273
<h2 class="mb-4">{{ $t('template_advanced') }}</h2>
238274

239275
<div class="mb-4">
240-
<v-text-field
241-
v-model="item.git_branch"
242-
:label="fieldLabel('branch')"
243-
outlined
244-
dense
245-
:disabled="formSaving"
246-
:placeholder="$t('branch')"
247-
></v-text-field>
248276

249277
<v-autocomplete
250278
v-if="premiumFeatures.project_runners"
@@ -533,10 +561,22 @@ export default {
533561
534562
args: [],
535563
runnerTags: null,
564+
branches: null,
565+
setBranch: false,
536566
};
537567
},
538568
539569
watch: {
570+
gitBranch() {
571+
this.setBranch = false;
572+
},
573+
574+
async repositoryId() {
575+
this.branches = null;
576+
577+
await this.loadBranches();
578+
},
579+
540580
needReset(val) {
541581
if (val) {
542582
if (this.item != null) {
@@ -555,7 +595,19 @@ export default {
555595
},
556596
},
557597
598+
async created() {
599+
await this.loadBranches();
600+
},
601+
558602
computed: {
603+
repositoryId() {
604+
return this.item?.repository_id;
605+
},
606+
607+
gitBranch() {
608+
return this.item?.git_branch;
609+
},
610+
559611
allow_override_inventory: {
560612
get() {
561613
return this.item.task_params.allow_override_inventory;
@@ -630,6 +682,16 @@ export default {
630682
},
631683
632684
methods: {
685+
async loadBranches() {
686+
if (this.repositoryId == null) {
687+
return;
688+
}
689+
690+
this.branches = await this.loadProjectEndpoint(
691+
`/repositories/${this.repositoryId}/branches`,
692+
);
693+
},
694+
633695
validateBackendFilename(v) {
634696
if (!v) {
635697
return true;

0 commit comments

Comments
 (0)