Ejemplo n.º 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)
		}

	}

}
Ejemplo n.º 2
0
func New(message string) pull.Middleware {
	return func(client *github.Client, event *github.PullRequest) {
		user, repo, number := pull.Data(event)

		config := &github.IssueRequest{
			State: github.String("closed"),
		}

		comment := &github.IssueComment{Body: github.String(message)}

		client.Issues.CreateComment(user, repo, number, comment)
		client.Issues.Edit(user, repo, number, config)

	}
}
Ejemplo n.º 3
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)
		}
	}
}