Woodpecker Plugin for creating netlify previews on PRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
932 B

package main
import (
"fmt"
"os"
"strings"
"code.gitea.io/sdk/gitea"
env "go.jolheiser.com/woodpecker-env"
)
func giteaComment(giteaURL, giteaToken, comment string, prIndex int) (*gitea.Comment, error) {
giteaClient, err := gitea.NewClient(giteaURL, gitea.SetToken(giteaToken))
if err != nil {
return nil, err
}
user, _, err := giteaClient.GetMyUserInfo()
if err != nil {
return nil, err
}
userRepo := strings.Split(env.CI_REPO_NAME, "/")
comments, _, err := giteaClient.ListIssueComments(userRepo[0], userRepo[1], int64(prIndex), gitea.ListIssueCommentOptions{})
for _, comm := range comments {
if comm.Poster.ID == user.ID {
return nil, fmt.Errorf("PR #%d already has a preview comment, skipping...", prIndex)
}
}
comm := os.ExpandEnv(comment)
c, _, err := giteaClient.CreateIssueComment(userRepo[0], userRepo[1], int64(prIndex), gitea.CreateIssueCommentOption{
Body: comm,
})
return c, err
}