commit
e236e24de3
1 changed files with 27 additions and 39 deletions
66
bot/utils.go
66
bot/utils.go
|
@ -19,23 +19,11 @@ var client = github.NewClient(&http.Client{Transport: itr})
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
|
|
||||||
func initGitHubClient() {
|
func initGitHubClient() {
|
||||||
readme, _, err := client.Repositories.GetReadme(ctx, "rowbawts", "theopenestsource", nil)
|
log.Println("Initializing......")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := readme.GetContent()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenForWebhook() {
|
func listenForWebhook() {
|
||||||
fmt.Println("Listening on :3333......")
|
log.Println("Listening on :3333......")
|
||||||
|
|
||||||
http.HandleFunc("/", webhookHandler)
|
http.HandleFunc("/", webhookHandler)
|
||||||
|
|
||||||
|
@ -115,36 +103,36 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
for _, comment := range comments {
|
for _, comment := range comments {
|
||||||
if strings.Contains(comment.GetBody(), "+1") {
|
if strings.Contains(comment.GetBody(), "+1") {
|
||||||
reactionCount++
|
reactionCount++
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if reactionCount >= reactionCountGoal {
|
if reactionCount >= reactionCountGoal {
|
||||||
// Merge the pull request
|
// Merge the pull request
|
||||||
merge := &github.PullRequestOptions{
|
merge := &github.PullRequestOptions{
|
||||||
MergeMethod: "merge", // Change this as needed
|
MergeMethod: "merge", // Change this as needed
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := client.PullRequests.Merge(ctx, owner, repo, prNumber, "Merging based on reactions", merge)
|
_, _, err := client.PullRequests.Merge(ctx, owner, repo, prNumber, "Merging based on reactions", merge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error merging pull request:", err)
|
log.Println("Error merging pull request:", err)
|
||||||
} else {
|
} else {
|
||||||
log.Println("Pull request merged successfully")
|
log.Println("Pull request merged successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
commentText := "Current :+1: count is (#{reactionCount}) need (#{reactionRemainingCount}) more to merge"
|
commentText := "Current :+1: count is (#{reactionCount}) need (#{reactionRemainingCount}) more to merge"
|
||||||
commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1)
|
commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1)
|
||||||
commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1)
|
commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1)
|
||||||
|
|
||||||
// Respond with a comment
|
// Respond with a comment
|
||||||
comment := &github.IssueComment{
|
comment := &github.IssueComment{
|
||||||
Body: github.String(commentText),
|
Body: github.String(commentText),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment)
|
_, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error creating comment:", err)
|
log.Println("Error creating comment:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue