Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Testsuite Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Feneas
federation
Testsuite Server
Commits
936695e6
Commit
936695e6
authored
Mar 17, 2018
by
zauberstuhl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check commit message for opt-in/out as well
parent
9b2e706b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
17 deletions
+42
-17
webhook.go
webhook.go
+42
-17
No files found.
webhook.go
View file @
936695e6
...
...
@@ -26,6 +26,7 @@ import (
"github.com/jinzhu/gorm"
_
"github.com/jinzhu/gorm/dialects/sqlite"
"strings"
"context"
)
func
webhook
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -55,16 +56,18 @@ func webhook(w http.ResponseWriter, r *http.Request) {
}
// skip all events except for open PRs
if
*
pr
.
State
!=
"open"
{
if
pr
.
GetState
()
!=
"open"
{
logger
.
Println
(
"Ignore closed pull request"
)
fmt
.
Fprintf
(
w
,
`{}`
)
return
}
var
repo
Repo
err
=
db
.
Where
(
"slug = ?"
,
*
pr
.
Base
.
Repo
.
FullName
)
.
Find
(
&
repo
)
.
Error
err
=
db
.
Where
(
"slug = ?"
,
pr
.
GetBase
()
.
GetRepo
()
.
GetFullName
(),
)
.
Find
(
&
repo
)
.
Error
if
err
!=
nil
{
logger
.
Println
(
err
,
*
pr
.
Base
.
Repo
.
FullName
)
logger
.
Println
(
err
,
pr
.
GetBase
()
.
GetRepo
()
.
GetFullName
()
)
fmt
.
Fprintf
(
w
,
`{"error":"repo not registered"}`
)
return
}
...
...
@@ -84,28 +87,47 @@ func webhook(w http.ResponseWriter, r *http.Request) {
}
// check PR title and body for [ci] or [ci skip] flag
if
pr
.
Title
!=
nil
&&
pr
.
Body
!=
nil
&&
strings
.
Contains
(
strings
.
ToLower
(
*
pr
.
Title
),
fmt
.
Sprintf
(
"[%s]"
,
buildFlag
))
&&
strings
.
Contains
(
strings
.
ToLower
(
*
pr
.
Body
),
if
pr
.
Title
!=
nil
&&
strings
.
Contains
(
strings
.
ToLower
(
*
pr
.
Title
),
fmt
.
Sprintf
(
"[%s]"
,
buildFlag
))
{
flagExists
=
true
}
if
!
flagExists
{
}
else
if
pr
.
Body
!=
nil
&&
strings
.
Contains
(
strings
.
ToLower
(
*
pr
.
Body
),
fmt
.
Sprintf
(
"[%s]"
,
buildFlag
))
{
flagExists
=
true
}
else
{
// check labels for build flag if we haven't already found it
for
_
,
label
:=
range
pr
.
Labels
{
if
label
.
Name
!=
nil
&&
strings
.
Contains
(
strings
.
ToLower
(
*
label
.
Name
),
buildFlag
)
{
strings
.
ToLower
(
label
.
GetName
()
),
buildFlag
)
{
flagExists
=
true
break
}
}
if
!
flagExists
{
// last but not least check the commit message for flags
var
prService
github
.
PullRequestsService
commits
,
_
,
err
:=
prService
.
ListCommits
(
context
.
Background
(),
pr
.
GetHead
()
.
GetUser
()
.
GetLogin
(),
pr
.
GetHead
()
.
GetRepo
()
.
GetName
(),
pr
.
GetNumber
(),
&
github
.
ListOptions
{})
if
err
==
nil
&&
len
(
commits
)
>
0
{
// check only last commit since older ones are irrelevant
commitMsg
:=
strings
.
ToLower
(
commits
[
0
]
.
GetCommit
()
.
GetMessage
())
flagExists
=
strings
.
Contains
(
commitMsg
,
fmt
.
Sprintf
(
"[%s]"
,
buildFlag
))
}
else
{
logger
.
Printf
(
"Commits is empty or an error occurred: %+v
\n
"
,
err
)
}
}
}
// ignoring pull-request! Repository is set
// to opt-in and no build flag was found
if
repo
.
OptIn
&&
!
flagExists
{
logger
.
Printf
(
"Ignore optin=%t buildFlag=%s flagExists=%t
\n
"
,
repo
.
OptIn
,
buildFlag
,
flagExists
)
fmt
.
Fprintf
(
w
,
`{}`
)
return
}
...
...
@@ -113,6 +135,9 @@ func webhook(w http.ResponseWriter, r *http.Request) {
// ignoring pull-request! Repository is set
// to opt-out and a skip flag was found
if
!
repo
.
OptIn
&&
flagExists
{
logger
.
Printf
(
"Ignore optin=%t buildFlag=%s flagExists=%t
\n
"
,
repo
.
OptIn
,
buildFlag
,
flagExists
)
fmt
.
Fprintf
(
w
,
`{}`
)
return
}
...
...
@@ -122,19 +147,19 @@ func webhook(w http.ResponseWriter, r *http.Request) {
Matrix
:
fmt
.
Sprintf
(
`"PROJECT=%s PRREPO=%s PRSHA=%s"`
,
repo
.
Project
,
*
pr
.
Head
.
Repo
.
CloneURL
,
*
pr
.
Head
.
SHA
,
pr
.
GetHead
()
.
GetRepo
()
.
GetCloneURL
()
,
pr
.
GetHead
()
.
GetSHA
()
,
),
PRUser
:
*
pr
.
Head
.
User
.
Login
,
PRRepo
:
*
pr
.
Head
.
Repo
.
Name
,
PRSha
:
*
pr
.
Head
.
SHA
,
PRUser
:
pr
.
GetHead
()
.
GetUser
()
.
GetLogin
()
,
PRRepo
:
pr
.
GetHead
()
.
GetRepo
()
.
GetName
()
,
PRSha
:
pr
.
GetHead
()
.
GetSHA
()
,
}
err
=
db
.
Create
(
&
build
)
.
Error
if
err
!=
nil
{
logger
.
Println
(
err
)
fmt
.
Fprintf
(
w
,
`{"error":"database error"}`
)
return
}
fmt
.
Fprintf
(
w
,
`{}`
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment