Add extra context for PRs #12

Merged
jolheiser merged 1 commits from pr into main 2022-09-07 16:28:34 +00:00
4 changed files with 91 additions and 25 deletions

@ -163,6 +163,28 @@ func forgeIssue(ctx *Context, num int) (discord.Embed, error) {
Value: state,
Inline: true,
})
if issue.PullRequest != nil {
canMerge := "❌"
if issue.PullRequest.CanMerge {
canMerge = "✅"
}
embed.Fields = append(embed.Fields, []discord.EmbedField{
{
Name: "Can Merge",
Value: canMerge,
Inline: true,
},
{
Name: "URLs",
Value: fmt.Sprintf("[Diff](%s) • [Patch](%s)", issue.PullRequest.Diff, issue.PullRequest.Patch),
Inline: true,
},
{
Name: "Branch Context",
Value: fmt.Sprintf("`%s` ⬅️ `%s`", issue.PullRequest.Base, issue.PullRequest.Head),
},
}...)
}
return embed, nil
}

@ -25,15 +25,25 @@ type Commit struct {
// Issue is a forge issue
type Issue struct {
User User
Title string
URL string
Body string
Labels []string
State string
Created time.Time
Closed time.Time
Comments int
User User
Title string
URL string
Body string
Labels []string
State string
Created time.Time
Closed time.Time
Comments int
PullRequest *PullRequest
}
// PullRequest is a forge pull request
type PullRequest struct {
CanMerge bool
Base string
Head string
Diff string
Patch string
}
// User is a forge user

@ -44,20 +44,37 @@ func (g *Gitea) Issue(num int) (*Issue, error) {
if issue.Closed != nil {
closed = *issue.Closed
}
var pr *PullRequest
if issue.PullRequest != nil {
pull, _, err := g.Client.GetPullRequest(giteaOrg, giteaRepo, int64(num))
if err != nil {
return nil, err
}
pr = &PullRequest{
CanMerge: pull.Mergeable,
Base: pull.Base.Name,
Head: pull.Head.Name,
Diff: pull.DiffURL,
Patch: pull.PatchURL,
}
}
return &Issue{
User: User{
Username: issue.Poster.UserName,
URL: fmt.Sprintf("https://gitea.com/%s", issue.Poster.UserName),
Image: issue.Poster.AvatarURL,
},
Title: issue.Title,
URL: issue.HTMLURL,
Body: issue.Body,
Labels: labels,
State: string(issue.State),
Created: issue.Created,
Closed: closed,
Comments: issue.Comments,
Title: issue.Title,
URL: issue.HTMLURL,
Body: issue.Body,
Labels: labels,
State: string(issue.State),
Created: issue.Created,
Closed: closed,
Comments: issue.Comments,
PullRequest: pr,
}, nil
}

@ -38,20 +38,37 @@ func (g *GitHub) Issue(num int) (*Issue, error) {
labels = append(labels, label.GetName())
}
sort.Strings(labels)
var pr *PullRequest
if issue.IsPullRequest() {
pull, _, err := g.Client.PullRequests.Get(context.Background(), githubOrg, githubRepo, num)
if err != nil {
return nil, err
}
pr = &PullRequest{
CanMerge: pull.GetMergeable(),
Base: pull.GetBase().GetLabel(),
Head: pull.GetHead().GetLabel(),
Diff: pull.GetDiffURL(),
Patch: pull.GetPatchURL(),
}
}
return &Issue{
User: User{
Username: issue.GetUser().GetLogin(),
URL: issue.GetUser().GetHTMLURL(),
Image: issue.GetUser().GetAvatarURL(),
},
Title: issue.GetTitle(),
URL: issue.GetHTMLURL(),
Body: issue.GetBody(),
Labels: labels,
State: issue.GetState(),
Created: issue.GetCreatedAt(),
Closed: issue.GetClosedAt(),
Comments: issue.GetComments(),
Title: issue.GetTitle(),
URL: issue.GetHTMLURL(),
Body: issue.GetBody(),
Labels: labels,
State: issue.GetState(),
Created: issue.GetCreatedAt(),
Closed: issue.GetClosedAt(),
Comments: issue.GetComments(),
PullRequest: pr,
}, nil
}