Skip to content

Commit

Permalink
add branch to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy76 committed Jan 7, 2025
1 parent c8bca60 commit 98d5165
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- YTT extra environment variable (see help)
- Role options (showDesigner, showLogs, showSettings, ...) allowing for custom semi-admin or designer roles
- Added branch to repos

## [5.0.7] - 2024-10-03

Expand Down
13 changes: 11 additions & 2 deletions client/src/views/Repos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</div>
<BulmaAdminTable
:dataList="repositoryList"
:labels="['Name','Status','Head','Type']"
:columns="['name','status','head','icon']"
:labels="['Name','Branch','Status','Head','Type']"
:columns="['name','branch','status','head','icon']"
:filters="['name','status']"
:icons="[false,false,false,true]"
identifier="name"
Expand All @@ -45,6 +45,7 @@
<transition name="add-column" appear>
<div class="column" v-if="repositoryItem!==undefined && !showDelete">
<BulmaInput icon="heading" v-model="repository.name" label="Name" placeholder="my_repo_name" :readonly="repositoryItem!==-1" :required="true" :hasError="v$.repository.name.$invalid" :errors="[]" help="Alphanumeric with underscore and hyphen" />
<BulmaInput icon="code-branch" v-model="repository.branch" label="Branch" placeholder="master" :hasError="v$.repository.branch.$invalid" :errors="[]" />
<BulmaInput icon="user" v-model="repository.user" label="Username" placeholder="my-user" :hasError="v$.repository.user.$invalid" :errors="[]" help="Alphanumeric with hyphen" />
<BulmaInput icon="lock" v-model="repository.password" type="password" label="Password" placeholder="Password or Token" />
<BulmaInput :icon="['fab','git']" v-model="repository.uri" label="Uri" placeholder="https://github.com/account/repo.git" :required="true" :hasError="v$.repository.uri.$invalid" :errors="[]" help="Only ssh or https uri's are allowed" />
Expand Down Expand Up @@ -78,6 +79,7 @@
import { useVuelidate } from '@vuelidate/core'
import { required, helpers } from '@vuelidate/validators'
export default{
name:"AfRepositories",
props:{
Expand All @@ -92,6 +94,7 @@
return {
repository:{
name:"",
branch:"",
user:"",
password:"",
uri:"",
Expand Down Expand Up @@ -266,6 +269,12 @@
(value) => !helpers.req(value) || (new RegExp("^[a-zA-Z0-9_-]{1,50}$").test(value)) // eslint-disable-line
)
},
branch: {
regex : helpers.withParams(
{description: "Must be valid git branch name",type:"regex"},
(value) => !helpers.req(value) || (new RegExp("^[^\s]+$").test(value)) // eslint-disable-line
)
},
uri: {
required,
regex : helpers.withParams(
Expand Down
8 changes: 6 additions & 2 deletions server/src/models/repo.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Repo.info = async function (name) {
};

// run git clone
Repo.clone = async function (uri,name) {
Repo.clone = async function (uri,name,branch=undefined) {

var directory = config.repoPath
var exists = true
Expand Down Expand Up @@ -194,7 +194,11 @@ Repo.clone = async function (uri,name) {

var cmd
if(uri){
cmd = `git clone --verbose ${uri} ${name}`
if(branch){
cmd = `git clone -b ${branch} --verbose ${uri} ${name}`
}else{
cmd = `git clone --verbose ${uri} ${name}`
}
}else{
throw new Error("No uri given")
}
Expand Down
6 changes: 4 additions & 2 deletions server/src/models/repository.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Repository=function(repository){
this.uri = repository.uri;
this.cron = repository.cron;
this.user = repository.user;
this.branch = repository.branch; // added in 5.0.8
this.use_for_forms = (repository.use_for_forms)?1:0;
this.rebase_on_start = (repository.rebase_on_start)?1:0;
this.use_for_playbooks = (repository.use_for_playbooks)?1:0;
Expand Down Expand Up @@ -56,7 +57,7 @@ Repository.delete = function(name){
};
Repository.findAll = function () {
// logger.info("Finding all repositories")
return mysql.do("SELECT id,name,user,uri,description,use_for_forms,use_for_playbooks,cron,status,output,head,rebase_on_start FROM AnsibleForms.`repositories`;",undefined,true)
return mysql.do("SELECT id,name,branch,user,uri,description,use_for_forms,use_for_playbooks,cron,status,output,head,rebase_on_start FROM AnsibleForms.`repositories`;",undefined,true)
};
// Repository.findById = function (id) {
// logger.info(`Finding repository ${id}`)
Expand Down Expand Up @@ -165,7 +166,8 @@ Repository.clone = async function(name){
await mysql.do("update AnsibleForms.`repositories` set status = ? where name = ?",["running",name])
var repo = await Repository.findByName(name)
var uri = Repository.getPrivateUri(repo)
output = await Repo.clone(uri,name)
var branch = repo.branch || undefined
output = await Repo.clone(uri,name,branch)
status="success"
}catch(e){
output = e.message
Expand Down

0 comments on commit 98d5165

Please sign in to comment.