36 lines
932 B
Go
36 lines
932 B
Go
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
|
|
}
|