.
This commit is contained in:
parent
6d650d68b1
commit
18bfc87a1c
@ -30,21 +30,20 @@ func (h *RequestHandler) allocateGiteaTransport() (*transport.Runtime, *apiclien
|
||||
|
||||
const (
|
||||
// from Gitea
|
||||
// ReviewStateApproved pr is approved
|
||||
ReviewStateApproved models.ReviewStateType = "APPROVED"
|
||||
// ReviewStatePending pr state is pending
|
||||
ReviewStatePending models.ReviewStateType = "PENDING"
|
||||
// ReviewStateComment is a comment review
|
||||
ReviewStateComment models.ReviewStateType = "COMMENT"
|
||||
// ReviewStateRequestChanges changes for pr are requested
|
||||
ReviewStateRequestChanges models.ReviewStateType = "REQUEST_CHANGES"
|
||||
// ReviewStateRequestReview review is requested from user
|
||||
ReviewStateRequestReview models.ReviewStateType = "REQUEST_REVIEW"
|
||||
// ReviewStateUnknown state of pr is unknown
|
||||
ReviewStateUnknown models.ReviewStateType = ""
|
||||
// ReviewStateApproved pr is approved
|
||||
ReviewStateApproved models.ReviewStateType = "APPROVED"
|
||||
// ReviewStatePending pr state is pending
|
||||
ReviewStatePending models.ReviewStateType = "PENDING"
|
||||
// ReviewStateComment is a comment review
|
||||
ReviewStateComment models.ReviewStateType = "COMMENT"
|
||||
// ReviewStateRequestChanges changes for pr are requested
|
||||
ReviewStateRequestChanges models.ReviewStateType = "REQUEST_CHANGES"
|
||||
// ReviewStateRequestReview review is requested from user
|
||||
ReviewStateRequestReview models.ReviewStateType = "REQUEST_REVIEW"
|
||||
// ReviewStateUnknown state of pr is unknown
|
||||
ReviewStateUnknown models.ReviewStateType = ""
|
||||
)
|
||||
|
||||
|
||||
func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64) (*models.PullRequest, []*models.PullReview, error) {
|
||||
if h.HasError() {
|
||||
return nil, nil, h.Error
|
||||
@ -56,12 +55,12 @@ func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64
|
||||
WithDefaults().
|
||||
WithOwner(org).
|
||||
WithRepo(project).
|
||||
WithIndex(num),
|
||||
WithIndex(num),
|
||||
transport.DefaultAuthentication,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
h.Error = err;
|
||||
h.Error = err
|
||||
h.LogPlainError(err)
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -86,7 +85,7 @@ func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64
|
||||
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() {
|
||||
return nil, h.Error
|
||||
}
|
||||
@ -95,14 +94,14 @@ func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.Notificat
|
||||
transport, client := h.allocateGiteaTransport()
|
||||
|
||||
params := notification.NewNotifyGetListParams().
|
||||
WithDefaults().
|
||||
WithLimit(&bigLimit)
|
||||
WithDefaults().
|
||||
WithLimit(&bigLimit)
|
||||
|
||||
if since != nil {
|
||||
s := strfmt.DateTime(*since)
|
||||
params.SetSince(&s)
|
||||
}
|
||||
|
||||
|
||||
list, err := client.Notification.NotifyGetList(params, transport.DefaultAuthentication)
|
||||
if err != nil {
|
||||
h.Error = err
|
||||
@ -335,3 +334,31 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.Pu
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ type ObsClient struct {
|
||||
client *http.Client
|
||||
user, password string
|
||||
cookie string
|
||||
|
||||
HomeProject string
|
||||
}
|
||||
|
||||
func NewObsClient(host string) (*ObsClient, error) {
|
||||
@ -27,6 +29,8 @@ func NewObsClient(host string) (*ObsClient, error) {
|
||||
client: &http.Client{},
|
||||
user: obsUser,
|
||||
password: obsPassword,
|
||||
|
||||
HomeProject: fmt.Sprintf("home:%s", obsUser),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
||||
|
||||
switch review.State {
|
||||
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
|
||||
|
||||
// create build project, if doesn't exist, and add it to pending requests
|
||||
case common.ReviewStatePending:
|
||||
// waiting for build results
|
||||
|
Loading…
Reference in New Issue
Block a user