mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-18 14:36:30 +00:00
Some optimizations
This commit is contained in:
parent
6854d1343e
commit
9ded21d792
5 changed files with 12 additions and 44 deletions
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
|
@ -12,7 +12,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/Bugagazavr/go-gitlab-client",
|
"ImportPath": "github.com/Bugagazavr/go-gitlab-client",
|
||||||
"Rev": "fa361f26087a2ff8fbb267fbe2d82037fc35e51a"
|
"Rev": "e5999f934dc45c41073fc57998a1224a75ff7d50"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/BurntSushi/migration",
|
"ImportPath": "github.com/BurntSushi/migration",
|
||||||
|
|
21
Godeps/_workspace/src/github.com/Bugagazavr/go-gitlab-client/examples/projects/main.go
generated
vendored
21
Godeps/_workspace/src/github.com/Bugagazavr/go-gitlab-client/examples/projects/main.go
generated
vendored
|
@ -43,8 +43,7 @@ func main() {
|
||||||
" > -m merge_requests -id PROJECT_ID\n"+
|
" > -m merge_requests -id PROJECT_ID\n"+
|
||||||
" > -m merge_request_notes -id PROJECT_ID -merge_id MERGE_REQUEST_ID\n"+
|
" > -m merge_request_notes -id PROJECT_ID -merge_id MERGE_REQUEST_ID\n"+
|
||||||
" > -m merge_request_comment -id PROJECT_ID -merge_id MERGE_REQUEST_ID -comment COMMENT_BODY\n"+
|
" > -m merge_request_comment -id PROJECT_ID -merge_id MERGE_REQUEST_ID -comment COMMENT_BODY\n"+
|
||||||
" > -m team -id PROJECT_ID\n"+
|
" > -m team -id PROJECT_ID")
|
||||||
" > -m add_drone -id PROJECT_ID\n -token DRONE_TOKEN -url DRONE_URL")
|
|
||||||
|
|
||||||
var id string
|
var id string
|
||||||
flag.StringVar(&id, "id", "", "Specify repository id")
|
flag.StringVar(&id, "id", "", "Specify repository id")
|
||||||
|
@ -55,12 +54,6 @@ func main() {
|
||||||
var comment string
|
var comment string
|
||||||
flag.StringVar(&comment, "comment", "", "The body of the new comment")
|
flag.StringVar(&comment, "comment", "", "The body of the new comment")
|
||||||
|
|
||||||
var drone_token string
|
|
||||||
flag.StringVar(&drone_token, "drone_token", "", "Drone service token")
|
|
||||||
|
|
||||||
var drone_url string
|
|
||||||
flag.StringVar(&drone_url, "drone_url", "", "Drone service url")
|
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Printf("Usage:\n")
|
fmt.Printf("Usage:\n")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
@ -249,17 +242,5 @@ func main() {
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
fmt.Printf("> [%d] %s (%s) since %s\n", member.Id, member.Username, member.Name, member.CreatedAt)
|
fmt.Printf("> [%d] %s (%s) since %s\n", member.Id, member.Username, member.Name, member.CreatedAt)
|
||||||
}
|
}
|
||||||
case "add_drone":
|
|
||||||
fmt.Println("Adding drone service to project")
|
|
||||||
|
|
||||||
if id == "" || drone_token == "" || drone_url == "" {
|
|
||||||
flag.Usage()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gitlab.AddDroneService(id, map[string]string{"token": drone_token, "drone_url": drone_url}); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
Godeps/_workspace/src/github.com/Bugagazavr/go-gitlab-client/hook_payload.go
generated
vendored
3
Godeps/_workspace/src/github.com/Bugagazavr/go-gitlab-client/hook_payload.go
generated
vendored
|
@ -27,7 +27,7 @@ type HookObjAttr struct {
|
||||||
StDiffs string `json:"st_diffs,omitempty"`
|
StDiffs string `json:"st_diffs,omitempty"`
|
||||||
MergeStatus string `json:"merge_status,omitempty"`
|
MergeStatus string `json:"merge_status,omitempty"`
|
||||||
TargetProjectId int `json:"target_project_id,omitempty"`
|
TargetProjectId int `json:"target_project_id,omitempty"`
|
||||||
URL string `json:"url,omitempty"`
|
Url string `json:"url,omiyempty"`
|
||||||
Source *hProject `json:"source,omitempty"`
|
Source *hProject `json:"source,omitempty"`
|
||||||
Target *hProject `json:"target,omitempty"`
|
Target *hProject `json:"target,omitempty"`
|
||||||
LastCommit *hCommit `json:"last_commit,omitempty"`
|
LastCommit *hCommit `json:"last_commit,omitempty"`
|
||||||
|
@ -38,6 +38,7 @@ type hProject struct {
|
||||||
SshUrl string `json:"ssh_url"`
|
SshUrl string `json:"ssh_url"`
|
||||||
HttpUrl string `json:"http_url"`
|
HttpUrl string `json:"http_url"`
|
||||||
VisibilityLevel int `json:"visibility_level"`
|
VisibilityLevel int `json:"visibility_level"`
|
||||||
|
WebUrl string `json:"web_url"`
|
||||||
Namespace string `json:"namespace"`
|
Namespace string `json:"namespace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/drone/drone/Godeps/_workspace/src/github.com/Bugagazavr/go-gitlab-client"
|
"github.com/drone/drone/Godeps/_workspace/src/github.com/Bugagazavr/go-gitlab-client"
|
||||||
"github.com/drone/drone/Godeps/_workspace/src/github.com/hashicorp/golang-lru"
|
"github.com/drone/drone/Godeps/_workspace/src/github.com/hashicorp/golang-lru"
|
||||||
|
@ -232,17 +230,8 @@ func (r *Gitlab) Hook(req *http.Request) (*common.Hook, error) {
|
||||||
|
|
||||||
switch parsed.ObjectKind {
|
switch parsed.ObjectKind {
|
||||||
case "merge_request":
|
case "merge_request":
|
||||||
if parsed.ObjectAttributes.State != "reopened" && parsed.ObjectAttributes.MergeStatus != "unchecked" ||
|
|
||||||
parsed.ObjectAttributes.State != "opened" && parsed.ObjectAttributes.MergeStatus != "unchecked" {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return mergeRequest(parsed, req)
|
return mergeRequest(parsed, req)
|
||||||
case "tag_push", "push":
|
case "tag_push", "push":
|
||||||
if len(parsed.After) == 0 || parsed.TotalCommitsCount == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return push(parsed, req)
|
return push(parsed, req)
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -252,13 +241,11 @@ func (r *Gitlab) Hook(req *http.Request) (*common.Hook, error) {
|
||||||
func mergeRequest(parsed *gogitlab.HookPayload, req *http.Request) (*common.Hook, error) {
|
func mergeRequest(parsed *gogitlab.HookPayload, req *http.Request) (*common.Hook, error) {
|
||||||
var hook = new(common.Hook)
|
var hook = new(common.Hook)
|
||||||
|
|
||||||
re := regexp.MustCompile(".git$")
|
|
||||||
|
|
||||||
hook.Repo = &common.Repo{}
|
hook.Repo = &common.Repo{}
|
||||||
hook.Repo.Owner = req.FormValue("owner")
|
hook.Repo.Owner = req.FormValue("owner")
|
||||||
hook.Repo.Name = req.FormValue("name")
|
hook.Repo.Name = req.FormValue("name")
|
||||||
hook.Repo.FullName = fmt.Sprintf("%s/%s", hook.Repo.Owner, hook.Repo.Name)
|
hook.Repo.FullName = fmt.Sprintf("%s/%s", hook.Repo.Owner, hook.Repo.Name)
|
||||||
hook.Repo.Link = re.ReplaceAllString(parsed.ObjectAttributes.Target.HttpUrl, "$1")
|
hook.Repo.Link = parsed.ObjectAttributes.Target.WebUrl
|
||||||
hook.Repo.Clone = parsed.ObjectAttributes.Target.HttpUrl
|
hook.Repo.Clone = parsed.ObjectAttributes.Target.HttpUrl
|
||||||
hook.Repo.Branch = "master"
|
hook.Repo.Branch = "master"
|
||||||
|
|
||||||
|
@ -267,24 +254,23 @@ func mergeRequest(parsed *gogitlab.HookPayload, req *http.Request) (*common.Hook
|
||||||
hook.Commit.Sha = parsed.ObjectAttributes.LastCommit.Id
|
hook.Commit.Sha = parsed.ObjectAttributes.LastCommit.Id
|
||||||
hook.Commit.Remote = parsed.ObjectAttributes.Source.HttpUrl
|
hook.Commit.Remote = parsed.ObjectAttributes.Source.HttpUrl
|
||||||
|
|
||||||
if parsed.ObjectAttributes.Source.HttpUrl == parsed.ObjectAttributes.Target.HttpUrl {
|
if parsed.ObjectAttributes.SourceProjectId == parsed.ObjectAttributes.TargetProjectId {
|
||||||
hook.Commit.Ref = fmt.Sprintf("refs/heads/%s", parsed.ObjectAttributes.SourceBranch)
|
hook.Commit.Ref = fmt.Sprintf("refs/heads/%s", parsed.ObjectAttributes.SourceBranch)
|
||||||
hook.Commit.Branch = parsed.ObjectAttributes.SourceBranch
|
|
||||||
hook.Commit.Timestamp = time.Now().UTC().Format("2006-01-02 15:04:05.000000000 +0000 MST")
|
|
||||||
} else {
|
} else {
|
||||||
hook.Commit.Ref = fmt.Sprintf("refs/merge-requests/%d/head", parsed.ObjectAttributes.IId)
|
hook.Commit.Ref = fmt.Sprintf("refs/merge-requests/%d/head", parsed.ObjectAttributes.IId)
|
||||||
hook.Commit.Branch = parsed.ObjectAttributes.SourceBranch
|
|
||||||
hook.Commit.Timestamp = time.Now().UTC().Format("2006-01-02 15:04:05.000000000 +0000 MST")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hook.Commit.Branch = parsed.ObjectAttributes.SourceBranch
|
||||||
|
hook.Commit.Timestamp = parsed.ObjectAttributes.LastCommit.Timestamp
|
||||||
|
|
||||||
hook.Commit.Author = &common.Author{}
|
hook.Commit.Author = &common.Author{}
|
||||||
hook.Commit.Author.Login = parsed.ObjectAttributes.LastCommit.Author.Name
|
hook.Commit.Author.Login = parsed.ObjectAttributes.LastCommit.Author.Name
|
||||||
hook.Commit.Author.Email = parsed.ObjectAttributes.LastCommit.Author.Email
|
hook.Commit.Author.Email = parsed.ObjectAttributes.LastCommit.Author.Email
|
||||||
|
|
||||||
hook.PullRequest = &common.PullRequest{}
|
hook.PullRequest = &common.PullRequest{}
|
||||||
hook.PullRequest.Number = parsed.ObjectAttributes.IId
|
hook.PullRequest.Number = parsed.ObjectAttributes.IId
|
||||||
hook.PullRequest.Title = parsed.ObjectAttributes.Description
|
hook.PullRequest.Title = parsed.ObjectAttributes.Title
|
||||||
hook.PullRequest.Link = parsed.ObjectAttributes.URL
|
hook.PullRequest.Link = parsed.ObjectAttributes.Url
|
||||||
|
|
||||||
return hook, nil
|
return hook, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ func Test_Gitlab(t *testing.T) {
|
||||||
g.Assert(hook.Repo.Name).Equal("diaspora-client")
|
g.Assert(hook.Repo.Name).Equal("diaspora-client")
|
||||||
|
|
||||||
g.Assert(hook.PullRequest.Number).Equal(1)
|
g.Assert(hook.PullRequest.Number).Equal(1)
|
||||||
g.Assert(hook.PullRequest.Title).Equal("")
|
g.Assert(hook.PullRequest.Title).Equal("MS-Viewport")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue