This commit is contained in:
Adam Majer 2024-07-22 17:35:48 +02:00
parent 6d650d68b1
commit 18bfc87a1c
3 changed files with 51 additions and 19 deletions

View File

@ -44,7 +44,6 @@ const (
ReviewStateUnknown models.ReviewStateType = "" ReviewStateUnknown models.ReviewStateType = ""
) )
func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64) (*models.PullRequest, []*models.PullReview, error) { func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64) (*models.PullRequest, []*models.PullReview, error) {
if h.HasError() { if h.HasError() {
return nil, nil, h.Error return nil, nil, h.Error
@ -61,7 +60,7 @@ func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64
) )
if err != nil { if err != nil {
h.Error = err; h.Error = err
h.LogPlainError(err) h.LogPlainError(err)
return nil, nil, err return nil, nil, err
} }
@ -86,7 +85,7 @@ func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64
return pr.Payload, reviews.Payload, nil return pr.Payload, reviews.Payload, nil
} }
func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.NotificationThread, error){ func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.NotificationThread, error) {
if h.HasError() { if h.HasError() {
return nil, h.Error return nil, h.Error
} }
@ -335,3 +334,31 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.Pu
return nil return nil
} }
func (h *RequestHandler) GetRepositoryFileContent(pr *models.PullRequest, path string) ([]byte, error) {
if h.HasError() {
return nil, h.Error
}
transport, client := h.allocateGiteaTransport()
repo := pr.Head.Repo
file, err := client.Repository.RepoGetRawFile(
repository.NewRepoGetRawFileParams().
WithOwner(repo.Owner.UserName).
WithRepo(repo.Name).
WithFilepath(path).
WithRef(&pr.Head.Ref),
transport.DefaultAuthentication,
)
if err != nil {
return nil, err
}
if !file.IsSuccess() {
return nil, fmt.Errorf("Invalid response from server (%d): %s", file.Code(), file.Error())
}
return file.Body(), nil
}

View File

@ -14,6 +14,8 @@ type ObsClient struct {
client *http.Client client *http.Client
user, password string user, password string
cookie string cookie string
HomeProject string
} }
func NewObsClient(host string) (*ObsClient, error) { func NewObsClient(host string) (*ObsClient, error) {
@ -27,6 +29,8 @@ func NewObsClient(host string) (*ObsClient, error) {
client: &http.Client{}, client: &http.Client{},
user: obsUser, user: obsUser,
password: obsPassword, password: obsPassword,
HomeProject: fmt.Sprintf("home:%s", obsUser),
}, nil }, nil
} }

View File

@ -70,6 +70,7 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
switch review.State { switch review.State {
case common.ReviewStateUnknown, common.ReviewStateRequestReview: case common.ReviewStateUnknown, common.ReviewStateRequestReview:
// create build project, if doesn't exist, and add it to pending requests // create build project, if doesn't exist, and add it to pending requests
case common.ReviewStatePending: case common.ReviewStatePending:
// waiting for build results // waiting for build results