Skip to content

Commit

Permalink
Add custom build triggers to repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Matt committed Mar 17, 2018
1 parent 936695e commit 2cfaa0d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
19 changes: 13 additions & 6 deletions frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,25 @@ func resultPage(w http.ResponseWriter, r *http.Request) {
return
}

var optIn bool
if strings.ToUpper(r.URL.Query().Get("optin")) == "ON" {
optIn = true
}

secret := Secret(16)
repo := Repo{
Project: project,
Slug: repo,
Token: accessToken,
Secret: secret,
OptIn: optIn,
}

// set the repo to opt-in
if strings.ToUpper(r.URL.Query().Get("optin")) == "ON" {
repo.OptIn = true
}
// define custom opt-in flag
if r.URL.Query().Get("optinFlag") != "" {
repo.OptInFlag = r.URL.Query().Get("optinFlag")
}
// define custom opt-out flag
if r.URL.Query().Get("optoutFlag") != "" {
repo.OptOutFlag = r.URL.Query().Get("optoutFlag")
}

name := "web"
Expand Down
2 changes: 2 additions & 0 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Repo struct {
Token string
Secret string
OptIn bool
OptInFlag string `gorm:"default:'ci'"`
OptOutFlag string `gorm:"default:'ci skip'"`
}

type Repos []Repo
19 changes: 16 additions & 3 deletions templates/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@
<input type="checkbox" class="form-check-input" id="optinInput" name="optin" describedby="optinHelp">
<label class="form-check-label" for="optinInput">Check if you want to opt-in on a new test</label>
<small id="optinHelp" class="form-text text-muted">
That would mean that tests are triggered if you specify <code>[ci]</code> in the PR title, message
That would mean that tests are triggered if you specify <code>[ci]</code> in the PR title, body, commit-message
or if the PR was tagged with <span class="badge badge-primary">ci</span>. If you leave the box unchecked
tests will be triggered on every pull-request. However you can skip them by writing <code>[ci skip]</code> in the PR title,
message or if the PR was tagged with <span class="badge badge-primary">ci skip</span>.
tests will be triggered on every pull-request. However you can skip them by using <code>[ci skip]</code>
in the mentioned fields or tag it with <span class="badge badge-primary">ci skip</span>.
</small>
<div class="form-group">
<label for="optinFlagInput">(optional) Custom Flags</label>
<input type="text" class="form-control" id="optinFlagInput" name="optinFlag" aria-describedby="optinFlagHelp" placeholder="default is 'ci'">
<small id="optinFlagHelp" class="form-text text-muted">
If you want to use custom build triggers for opt-in you can specify it here.
</small>
</div>
<div class="form-group">
<input type="text" class="form-control" name="optoutFlag" aria-describedby="optoutFlagHelp" placeholder="default is 'ci skip'">
<small id="optoutFlagHelp" class="form-text text-muted">
If you want to use custom build triggers for opt-out you can specify it here.
</small>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Expand Down
4 changes: 2 additions & 2 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func webhook(w http.ResponseWriter, r *http.Request) {
//}

var flagExists = false
var buildFlag = "ci skip"
var buildFlag = repo.OptOutFlag
if repo.OptIn {
buildFlag = "ci"
buildFlag = repo.OptInFlag
}

// check PR title and body for [ci] or [ci skip] flag
Expand Down

0 comments on commit 2cfaa0d

Please sign in to comment.