This commit is contained in:
2024-07-18 16:43:27 +02:00
parent eda764b192
commit 7dfbf4c9f2
6 changed files with 123 additions and 27 deletions

View File

@@ -7,9 +7,12 @@ import (
"os"
"path/filepath"
"strings"
"time"
transport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
apiclient "src.opensuse.org/autogits/common/gitea-generated/client"
"src.opensuse.org/autogits/common/gitea-generated/client/notification"
"src.opensuse.org/autogits/common/gitea-generated/client/organization"
"src.opensuse.org/autogits/common/gitea-generated/client/repository"
"src.opensuse.org/autogits/common/gitea-generated/models"
@@ -25,6 +28,63 @@ func (h *RequestHandler) allocateGiteaTransport() (*transport.Runtime, *apiclien
return r, apiclient.New(r, nil)
}
func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.NotificationThread, error){
if h.HasError() {
return nil, h.Error
}
bigLimit := int64(100000)
transport, client := h.allocateGiteaTransport()
params := notification.NewNotifyGetListParams().
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
return nil, err
}
if !list.IsSuccess() {
h.Error = fmt.Errorf("Cannot fetch notifications: %s", list.Error())
return nil, h.Error
}
return list.Payload, nil
}
func (h *RequestHandler) SetNotificationRead(notificationId int) error {
if h.HasError() {
return h.Error
}
transport, client := h.allocateGiteaTransport()
list, err := client.Notification.NotifyReadThread(
notification.NewNotifyReadThreadParams().
WithDefaults().
WithID(string(id)),
transport.DefaultAuthentication,
)
if err != nil {
h.Error = err
return err
}
if !list.IsSuccess() {
h.Error = fmt.Errorf("Cannot update notifications: %d", notificationId)
return h.Error
}
return nil
}
func (h *RequestHandler) CreateRepositoryIfNotExist(org Organization, repoName string) *models.Repository {
if h.HasError() {
return nil
@@ -177,7 +237,7 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.Pu
transport, client := h.allocateGiteaTransport()
var page, maxSize int64;
var page, maxSize int64
page = 1
maxSize = 10000
state := "open"
@@ -204,7 +264,7 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.Pu
prLine := fmt.Sprintf(PrPattern, pr.Repository.Owner.Username, pr.Repository.Name, pr.Number)
h.Log("attemping to match line: '%s'", prLine)
// payload_processing:
// payload_processing:
for _, pr := range prs.Payload {
lines := strings.Split(pr.Body, "\n")