示例#1
0
func New(match string) pull.Middleware {
	return func(client *github.Client, event *github.PullRequest) {
		user, repo, number := pull.Data(event)

		commits, _, _ := client.PullRequests.ListCommits(user, repo, number, nil)
		files, _, _ := client.PullRequests.ListFiles(user, repo, number, nil)

		found := false
		for _, file := range files {
			found = strings.EqualFold(*file.Filename, match)
		}

		var message *github.RepoStatus
		url := "http://keepachangelog.com/"
		if found {
			message = pull.Success(url, "ChangeLog Kept", "changelog")
		} else {
			message = pull.Failure(url, "Keep a ChangeLog", "changelog")
		}

		for _, c := range commits {
			client.Repositories.CreateStatus(user, repo, *c.SHA, message)
		}

	}

}
示例#2
0
func Signed(client *github.Client, event *github.PullRequest) {
	user, repo, number := pull.Data(event)

	commits, _, _ := client.PullRequests.ListCommits(user, repo, number, nil)

	for _, c := range commits {
		r := fmt.Sprintf("Signed-off-by: .* <%s>", *c.Commit.Author.Email)
		match, _ := regexp.Match(r, []byte(*c.Commit.Message))

		if match {
			success := pull.Success("", "Commit is signed off", "signed")
			client.Repositories.CreateStatus(user, repo, *c.SHA, success)
		} else {
			s := fmt.Sprintf("Commit not signed off: [%s](%s).", *c.SHA, *c.HTMLURL)
			comment := &github.IssueComment{Body: &s}

			cm, _, _ := client.Issues.CreateComment(user, repo, number, comment)
			failure := pull.Failure(*cm.HTMLURL, "Commit is not signed off", "signed")
			client.Repositories.CreateStatus(user, repo, *c.SHA, failure)
		}
	}
}