This commit is contained in:
2024-12-16 18:12:54 +01:00
parent f6bd0c10c0
commit ac6fb96534
6 changed files with 92 additions and 56 deletions

View File

@@ -23,7 +23,6 @@ import (
"io"
"os"
"path/filepath"
"strings"
"time"
transport "github.com/go-openapi/runtime/client"
@@ -56,31 +55,39 @@ const (
ReviewStateUnknown models.ReviewStateType = ""
)
type GiteaPRFetcher interface {
GetAssociatedPRs(org, repo string, prNo int64) ([]*models.PullRequest, error)
}
type GiteaMaintainershipInterface interface {
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, error)
}
type Gitea interface {
type GiteaPRReviewFetcher interface {
GetPullRequestAndReviews(org, project string, num int64) (*models.PullRequest, []*models.PullReview, error)
}
type GiteaReviewRequester interface {
RequestReviews(pr *models.PullRequest, reviewer string) ([]*models.PullReview, error)
}
type GiteaReviewer interface {
AddReviewComment(pr *models.PullRequest, state models.ReviewStateType, comment string) (*models.PullReview, error)
}
type Gitea interface {
GiteaReviewRequester
GiteaReviewer
GiteaPRReviewFetcher
GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error)
SetNotificationRead(notificationId int64) error
GetOrganization(orgName string) (*models.Organization, error)
GetOrganizationRepositories(orgName string) ([]*models.Repository, error)
CreateRepositoryIfNotExist(git Git, org Organization, repoName string) (*models.Repository, error)
CreatePullRequestIfNotExist(repo *models.Repository, srcId, targetId, title, body string) (*models.PullRequest, error)
RequestReviews(pr *models.PullRequest, reviewer string) ([]*models.PullReview, error)
AddReviewComment(pr *models.PullRequest, state models.ReviewStateType, comment string) (*models.PullReview, error)
GetRepositoryFileContent(org, repo, hash, path string) ([]byte, error)
GetPullRequestFileContent(pr *models.PullRequest, path string) ([]byte, error)
GetRecentPullRequests(org, repo string) ([]*models.PullRequest, error)
GetRecentCommits(org, repo, branch string, commitNo int64) ([]*models.Commit, error)
GiteaMaintainershipInterface
GiteaPRFetcher
}
type GiteaTransport struct {
@@ -374,24 +381,6 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
return c.Payload, nil
}
func (gitea *GiteaTransport) GetAssociatedPRs(org, repo string, prNo int64) ([]*models.PullRequest, error) {
prData, err := gitea.client.Repository.RepoGetPullRequest(
repository.NewRepoGetPullRequestParams().
WithOwner(org).
WithRepo(repo).
WithIndex(prNo),
gitea.transport.DefaultAuthentication)
if err != nil {
return nil, err
}
desc := prData.Payload.Body
strings.Split(desc, "\n")
return nil, nil
}
func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path string) ([]byte, error) {
var retData []byte