forked from jzerebecki/autogits
Compare commits
185 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
151a38d163
|
||
|
|
c4dc21ac10
|
||
| 878df15e58 | |||
| c84af6286d | |||
| d2cbb8fd34 | |||
| 8436a49c5d | |||
| 106e36d6bf | |||
| 0ec4986163 | |||
| fb7f6adc98 | |||
| 231f29b065 | |||
| 3f3645a453 | |||
| 42e2713cd8 | |||
| 3d24dce5c0 | |||
| 0cefb45d8a | |||
| ddbb824006 | |||
| 69dac4ec31 | |||
| b7e03ab465 | |||
| 76aec3aabb | |||
| 19fb7e277b | |||
| 51261f1bc1 | |||
| 949810709d | |||
| c012570e89 | |||
| 44a3b15a7d | |||
| c5db1c83a7 | |||
| 9f0909621b | |||
| b3914b04bd | |||
| b43a19189e | |||
| 01b665230e | |||
| 1a07d4c541 | |||
| 22e44dff47 | |||
| f9021d08b9 | |||
| 7a0394e51b | |||
| 518bc15696 | |||
| 51873eb048 | |||
| 4f33ce979c | |||
| 7cc4db2283 | |||
| 4d9e2f8cab | |||
| ed4f27a19e | |||
| e438b5b064 | |||
| 885bb7e537 | |||
| 977d75f6e9 | |||
| 42a9ee48e0 | |||
| 9333e5c3da | |||
| 5e29c88dc8 | |||
| 4f0f101620 | |||
| 253f009da3 | |||
| 5e66a14fa9 | |||
| e79122e494 | |||
| 0b4b1a4e21 | |||
| 0019546e30 | |||
| 6438a8625a | |||
| 3928fa6429 | |||
| e92ac4a592 | |||
| a1520ebfb0 | |||
| c8d65a3ae5 | |||
| b849a72f31 | |||
| 568a2f3df8 | |||
| 30c8b2fe57 | |||
| 69b0f9a5ed | |||
| a283d4f26f | |||
| af898a6b8d | |||
| b89cdb7664 | |||
| d37bfaa9d3 | |||
| 90cca05b31 | |||
| 7c229500c1 | |||
| 290424c4a7 | |||
| 703fa101a4 | |||
| 66e4982e2d | |||
| 09b1c415dd | |||
| 629b941558 | |||
| aa50481c00 | |||
| bc714ee22d | |||
| b8cc0357a7 | |||
| aed0ac3ee9 | |||
| cca3575596 | |||
| 69dcebcf74 | |||
|
e5d07f0ce6
|
|||
|
df9478a920
|
|||
| 7da9daddd5 | |||
| cd0c3bc759 | |||
| af096af507 | |||
| d150c66427 | |||
| 3bef967023 | |||
| 9c3658b33e | |||
| 6968cbc942 | |||
| 2cb7a065a9 | |||
| 35058623a7 | |||
| 24fe165c46 | |||
| 1498438fee | |||
| 4653904ded | |||
| bd87bf8ce3 | |||
| 364c3f4ab7 | |||
| fd8b7f1bee | |||
| da32adb16b | |||
| 1b5a0ad0c8 | |||
| e78fdf4a09 | |||
| 0564a50fb5 | |||
| 4f7db36123 | |||
| 41d536ea1b | |||
| 91d915cc28 | |||
| c7a300119e | |||
| c5c3e1c115 | |||
| c93788d0ee | |||
| 1e46f8d0ab | |||
| 9963ae90ef | |||
| a9225bbd76 | |||
| 801fff6e22 | |||
| b4b0d075be | |||
| 16c2eb7090 | |||
| 3264ad1589 | |||
| cb64635aea | |||
| aeb4c20744 | |||
| da1df24666 | |||
| 6b3c613f14 | |||
| eb997e1ae9 | |||
| f52d72e04a | |||
| 23e2566843 | |||
| 0d0fcef7ac | |||
| 62a597718b | |||
| 327cb4ceaf | |||
| aac475ad16 | |||
| 046a60a6ed | |||
| dcf964bf7a | |||
| bff5f1cab7 | |||
| 6d1ef184e0 | |||
| e30d366f2f | |||
| 4a2fe06f05 | |||
| 210e7588f1 | |||
| 72b100124d | |||
| 996d36aaa8 | |||
| 82b5b105b1 | |||
| 248ec4d03c | |||
| faa21f5453 | |||
| 21c4a7c1e0 | |||
| f3f76e7d5b | |||
| e341b630a2 | |||
| 58532b9b60 | |||
| a697ccd0ca | |||
| 4bafe0b4ef | |||
| 7af2092ae1 | |||
| 32374f76c1 | |||
| 9403b563f6 | |||
| bd492f8d92 | |||
| fbc84d551d | |||
| 874a120f88 | |||
| 199396c210 | |||
| f0de3ad54a | |||
| bfeac63c57 | |||
| d65f37739c | |||
| 5895e3d02c | |||
| 0e036b5ec6 | |||
| 1d1602852c | |||
| 9b5013ee45 | |||
| ed815c3ad1 | |||
| 8645063e8d | |||
| 2d044d5664 | |||
| 51ba81f257 | |||
| bb7a247f66 | |||
| c1f71253a4 | |||
| 96e1c26600 | |||
| 9d9964df11 | |||
| e257b113b9 | |||
| 11e0bbaed1 | |||
| fb430d8c76 | |||
| 7ed2a7082d | |||
| ba7686189e | |||
| 9dcd25b69a | |||
| 881fad36a0 | |||
| 29906e22d2 | |||
| d89c77e22d | |||
| f91c61cd20 | |||
| 06aef50047 | |||
| 52a5cdea94 | |||
| d3f1b36676 | |||
| 5ea5f05b02 | |||
| 5877081280 | |||
| c4ce974ddf | |||
| 65c718e73b | |||
| a8e6c175c0 | |||
| 044416cd2a | |||
| 009cc88d54 | |||
| da1f4f4fa0 | |||
| cfad21e1a3 | |||
| 5eb54d40e0 | |||
| 80ff036acb |
26
.gitea/workflows/go-generate.yaml
Normal file
26
.gitea/workflows/go-generate.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
name: go-generate
|
||||
on:
|
||||
push:
|
||||
branches: ['main']
|
||||
pull_request:
|
||||
paths:
|
||||
- '**.go'
|
||||
- '**foo'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
go-generate:
|
||||
name: go-generate
|
||||
container:
|
||||
image: registry.opensuse.org/home/jzerebecki/branches/devel/factory/git-workflow/containers/opensuse/bci/golang-extended:latest
|
||||
steps:
|
||||
- run: git clone --no-checkout --depth 1 ${{ gitea.server_url }}/${{ gitea.repository }} .
|
||||
- run: git fetch origin ${{ gitea.ref }}
|
||||
- run: git checkout FETCH_HEAD
|
||||
- run: go generate -C common; go generate -C workflow-pr
|
||||
- run: echo ${{ github.event.number }}
|
||||
- run: echo ${{ github.event.pull_request.author_association }}
|
||||
- name: Check access
|
||||
if: ${{ github.event.pull_request.author_association != 'MEMBER' }}
|
||||
run: exit 1
|
||||
- run: 'git status --short; git status --porcelain=2|grep --quiet -v . || ( git add .; git config user.name "Gitea Actions"; git config user.email "gitea_noreply@opensuse.org"; git commit -m "CI run result of: go generate"; git show; git show --numstat; git push origin ${{ gitea.ref }} )'
|
||||
- run: git diff --numstat FETCH_HEAD HEAD
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
mock
|
||||
node_modules
|
||||
*.obscpio
|
||||
autogits-tmp.tar.zst
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
all: build
|
||||
|
||||
api.json:
|
||||
api.json::
|
||||
curl -o api.json https://src.opensuse.org/swagger.v1.json
|
||||
|
||||
gitea-generated/client/gitea_api_client.go:: api.json
|
||||
gitea-generated/client/gitea_api_client.go: api.json
|
||||
[ -d gitea-generated ] || mkdir gitea-generated
|
||||
podman run --rm -v $$(pwd):/api ghcr.io/go-swagger/go-swagger generate client -f /api/api.json -t /api/gitea-generated
|
||||
podman run --rm -v $$(pwd)/..:/api ghcr.io/go-swagger/go-swagger generate client -f /api/common/api.json -t /api/common/gitea-generated
|
||||
|
||||
api: gitea-generated/client/gitea_api_client.go mock_gitea_utils.go
|
||||
swagger: gitea-generated/client/gitea_api_client.go
|
||||
|
||||
api:
|
||||
go generate
|
||||
|
||||
build: api
|
||||
|
||||
1150
common/api.json
1150
common/api.json
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ type BasicPR struct {
|
||||
Num int64
|
||||
}
|
||||
|
||||
var validOrgAndRepoRx *regexp.Regexp = regexp.MustCompile("^[A-Za-z0-9_-]+$")
|
||||
var validOrgAndRepoRx *regexp.Regexp = regexp.MustCompile("^[A-Za-z0-9_\\.-]+$")
|
||||
|
||||
func parsePrLine(line string) (BasicPR, error) {
|
||||
var ret BasicPR
|
||||
|
||||
157
common/config.go
157
common/config.go
@@ -20,15 +20,35 @@ package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/tailscale/hujson"
|
||||
)
|
||||
|
||||
//go:generate mockgen -source=config.go -destination=mock/config.go -typed
|
||||
|
||||
const (
|
||||
ProjectConfigFile = "workflow.config"
|
||||
StagingConfigFile = "staging.config"
|
||||
)
|
||||
|
||||
type ConfigFile struct {
|
||||
GitProjectName []string
|
||||
GitProjectNames []string
|
||||
}
|
||||
|
||||
type ReviewGroup struct {
|
||||
Name string
|
||||
Reviewers []string
|
||||
}
|
||||
|
||||
type QAConfig struct {
|
||||
Name string
|
||||
Origin string
|
||||
}
|
||||
|
||||
type AutogitConfig struct {
|
||||
@@ -37,6 +57,12 @@ type AutogitConfig struct {
|
||||
GitProjectName string // Organization/GitProjectName.git is PrjGit
|
||||
Branch string // branch name of PkgGit that aligns with PrjGit submodules
|
||||
Reviewers []string // only used by `pr` workflow
|
||||
ReviewGroups []ReviewGroup
|
||||
Committers []string // group in addition to Reviewers and Maintainers that can order the bot around, mostly as helper for factory-maintainers
|
||||
Subdirs []string // list of directories to sort submodules into. Needed b/c _manifest cannot list non-existent directories
|
||||
|
||||
ManualMergeOnly bool // only merge with "Merge OK" comment by Project Maintainers and/or Package Maintainers and/or reviewers
|
||||
ManualMergeProject bool // require merge of ProjectGit PRs with "Merge OK" by ProjectMaintainers and/or reviewers
|
||||
}
|
||||
|
||||
type AutogitConfigs []*AutogitConfig
|
||||
@@ -48,7 +74,11 @@ func ReadConfig(reader io.Reader) (*ConfigFile, error) {
|
||||
}
|
||||
|
||||
config := ConfigFile{}
|
||||
if err := json.Unmarshal(data, &config.GitProjectName); err != nil {
|
||||
data, err = hujson.Standardize(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse json: %w", err)
|
||||
}
|
||||
if err := json.Unmarshal(data, &config.GitProjectNames); err != nil {
|
||||
return nil, fmt.Errorf("Error parsing Git Project paths: %w", err)
|
||||
}
|
||||
|
||||
@@ -65,7 +95,25 @@ func ReadConfigFile(filename string) (*ConfigFile, error) {
|
||||
return ReadConfig(file)
|
||||
}
|
||||
|
||||
func ReadWorkflowConfig(gitea Gitea, git_project string) (*AutogitConfig, error) {
|
||||
type GiteaFileContentAndRepoFetcher interface {
|
||||
GiteaFileContentReader
|
||||
GiteaRepoFetcher
|
||||
}
|
||||
|
||||
func UnmarshalWorkflowConfig(data []byte) (*AutogitConfig, error) {
|
||||
var config AutogitConfig
|
||||
data, err := hujson.Standardize(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse json: %w", err)
|
||||
}
|
||||
if err := json.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("Error parsing workflow config file: %s: %w", string(data), err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func ReadWorkflowConfig(gitea GiteaFileContentAndRepoFetcher, git_project string) (*AutogitConfig, error) {
|
||||
hash := strings.Split(git_project, "#")
|
||||
branch := ""
|
||||
if len(hash) > 1 {
|
||||
@@ -82,30 +130,34 @@ func ReadWorkflowConfig(gitea Gitea, git_project string) (*AutogitConfig, error)
|
||||
return nil, fmt.Errorf("Missing org/repo in projectgit: %s", git_project)
|
||||
}
|
||||
|
||||
data, _, err := gitea.GetRepositoryFileContent(a[0], prjGitRepo, branch, "workflow.config")
|
||||
data, _, err := gitea.GetRepositoryFileContent(a[0], prjGitRepo, branch, ProjectConfigFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error fetching 'workflow.config': %w", err)
|
||||
return nil, fmt.Errorf("Error fetching 'workflow.config' for %s/%s#%s: %w", a[0], prjGitRepo, branch, err)
|
||||
}
|
||||
|
||||
var config AutogitConfig
|
||||
if err := json.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("Error parsing config file: %w", err)
|
||||
config, err := UnmarshalWorkflowConfig(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config.GitProjectName = a[0] + "/" + prjGitRepo
|
||||
if len(branch) > 0 {
|
||||
config.GitProjectName = config.GitProjectName + "#" + branch
|
||||
}
|
||||
if len(config.Organization) < 1 {
|
||||
config.Organization = a[0]
|
||||
}
|
||||
log.Println(config)
|
||||
return &config, nil
|
||||
config.GitProjectName = a[0] + "/" + prjGitRepo
|
||||
if len(branch) == 0 {
|
||||
if r, err := gitea.GetRepository(a[0], prjGitRepo); err == nil {
|
||||
branch = r.DefaultBranch
|
||||
} else {
|
||||
return nil, fmt.Errorf("Failed to read workflow config in %s: %w", git_project, err)
|
||||
}
|
||||
}
|
||||
config.GitProjectName = config.GitProjectName + "#" + branch
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func ResolveWorkflowConfigs(gitea Gitea, config *ConfigFile) (AutogitConfigs, error) {
|
||||
configs := make([]*AutogitConfig, 0, len(config.GitProjectName))
|
||||
for _, git_project := range config.GitProjectName {
|
||||
func ResolveWorkflowConfigs(gitea GiteaFileContentAndRepoFetcher, config *ConfigFile) (AutogitConfigs, error) {
|
||||
configs := make([]*AutogitConfig, 0, len(config.GitProjectNames))
|
||||
for _, git_project := range config.GitProjectNames {
|
||||
c, err := ReadWorkflowConfig(gitea, git_project)
|
||||
if err != nil {
|
||||
// can't sync, so ignore for now
|
||||
@@ -119,7 +171,11 @@ func ResolveWorkflowConfigs(gitea Gitea, config *ConfigFile) (AutogitConfigs, er
|
||||
}
|
||||
|
||||
func (configs AutogitConfigs) GetPrjGitConfig(org, repo, branch string) *AutogitConfig {
|
||||
prjgit := org + "/" + repo + "#" + branch
|
||||
for _, c := range configs {
|
||||
if c.GitProjectName == prjgit {
|
||||
return c
|
||||
}
|
||||
if c.Organization == org && c.Branch == branch {
|
||||
return c
|
||||
}
|
||||
@@ -128,3 +184,70 @@ func (configs AutogitConfigs) GetPrjGitConfig(org, repo, branch string) *Autogit
|
||||
return nil
|
||||
}
|
||||
|
||||
func (config *AutogitConfig) GetReviewGroupMembers(reviewer string) ([]string, error) {
|
||||
for _, g := range config.ReviewGroups {
|
||||
if g.Name == reviewer {
|
||||
return g.Reviewers, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("User " + reviewer + " not found as group reviewer for " + config.GitProjectName)
|
||||
}
|
||||
|
||||
func (config *AutogitConfig) GetPrjGit() (string, string, string) {
|
||||
org := config.Organization
|
||||
repo := DefaultGitPrj
|
||||
branch := "master"
|
||||
|
||||
a := strings.Split(config.GitProjectName, "/")
|
||||
if len(a[0]) > 0 {
|
||||
repo = strings.TrimSpace(a[0])
|
||||
}
|
||||
if len(a) == 2 {
|
||||
if a[0] = strings.TrimSpace(a[0]); len(a[0]) > 0 {
|
||||
org = a[0]
|
||||
}
|
||||
repo = strings.TrimSpace(a[1])
|
||||
}
|
||||
b := strings.Split(repo, "#")
|
||||
if len(b) == 2 {
|
||||
if b[0] = strings.TrimSpace(b[0]); len(b[0]) > 0 {
|
||||
repo = b[0]
|
||||
} else {
|
||||
repo = DefaultGitPrj
|
||||
}
|
||||
if b[1] = strings.TrimSpace(b[1]); len(b[1]) > 0 {
|
||||
branch = strings.TrimSpace(b[1])
|
||||
}
|
||||
}
|
||||
|
||||
return org, repo, branch
|
||||
}
|
||||
|
||||
func (config *AutogitConfig) GetRemoteBranch() string {
|
||||
return "origin_" + config.Branch
|
||||
}
|
||||
|
||||
type StagingConfig struct {
|
||||
ObsProject string
|
||||
RebuildAll bool
|
||||
CleanupDelay int // cleanup delay, in hours, for unmerged closed PRs (def: 48)
|
||||
|
||||
// if set, then only use pull request numbers as unique identifiers
|
||||
StagingProject string
|
||||
QA []QAConfig
|
||||
}
|
||||
|
||||
func ParseStagingConfig(data []byte) (*StagingConfig, error) {
|
||||
var staging StagingConfig
|
||||
data, err := hujson.Standardize(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
staging.CleanupDelay = 48
|
||||
if err := json.Unmarshal(data, &staging); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &staging, nil
|
||||
}
|
||||
|
||||
190
common/config_test.go
Normal file
190
common/config_test.go
Normal file
@@ -0,0 +1,190 @@
|
||||
package common_test
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/mock/gomock"
|
||||
"src.opensuse.org/autogits/common"
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
mock_common "src.opensuse.org/autogits/common/mock"
|
||||
)
|
||||
|
||||
func TestProjectConfigMatcher(t *testing.T) {
|
||||
configs := common.AutogitConfigs{
|
||||
{
|
||||
Organization: "test",
|
||||
GitProjectName: "test/prjgit#main",
|
||||
},
|
||||
{
|
||||
Organization: "test",
|
||||
Branch: "main",
|
||||
GitProjectName: "test/prjgit#main",
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
org string
|
||||
repo string
|
||||
branch string
|
||||
config int
|
||||
}{
|
||||
{
|
||||
name: "invalid match",
|
||||
org: "foo",
|
||||
repo: "bar",
|
||||
config: -1,
|
||||
},
|
||||
{
|
||||
name: "default branch",
|
||||
org: "test",
|
||||
repo: "foo",
|
||||
branch: "",
|
||||
config: 0,
|
||||
},
|
||||
{
|
||||
name: "main branch",
|
||||
org: "test",
|
||||
repo: "foo",
|
||||
branch: "main",
|
||||
config: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
c := configs.GetPrjGitConfig(test.org, test.repo, test.branch)
|
||||
if test.config < 0 {
|
||||
if c != nil {
|
||||
t.Fatal("Expected nil. Got:", *c)
|
||||
}
|
||||
} else if config := configs[test.config]; c != config {
|
||||
t.Fatal("Expected", *config, "got", *c)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigWorkflowParser(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config_json string
|
||||
repo models.Repository
|
||||
}{
|
||||
{
|
||||
name: "Regular workflow file",
|
||||
config_json: `{
|
||||
"Workflows": ["direct", "pr"],
|
||||
"Organization": "testing",
|
||||
"ReviewGroups": [
|
||||
{
|
||||
"Name": "gnuman1",
|
||||
"Reviewers": ["adamm"]
|
||||
}
|
||||
]
|
||||
}`,
|
||||
repo: models.Repository{
|
||||
DefaultBranch: "master",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
gitea := mock_common.NewMockGiteaFileContentAndRepoFetcher(ctl)
|
||||
gitea.EXPECT().GetRepositoryFileContent("foo", "bar", "", "workflow.config").Return([]byte(test.config_json), "abc", nil)
|
||||
gitea.EXPECT().GetRepository("foo", "bar").Return(&test.repo, nil)
|
||||
|
||||
config, err := common.ReadWorkflowConfig(gitea, "foo/bar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if config.ManualMergeOnly != false {
|
||||
t.Fatal("This should be false")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectGitParser(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
prjgit string
|
||||
org string
|
||||
branch string
|
||||
res [3]string
|
||||
}{
|
||||
{
|
||||
name: "repo only",
|
||||
prjgit: "repo.git",
|
||||
org: "org",
|
||||
branch: "br",
|
||||
res: [3]string{"org", "repo.git", "master"},
|
||||
},
|
||||
{
|
||||
name: "default",
|
||||
org: "org",
|
||||
res: [3]string{"org", common.DefaultGitPrj, "master"},
|
||||
},
|
||||
{
|
||||
name: "repo with branch",
|
||||
org: "org2",
|
||||
prjgit: "repo.git#somebranch",
|
||||
res: [3]string{"org2", "repo.git", "somebranch"},
|
||||
},
|
||||
{
|
||||
name: "repo org and branch",
|
||||
org: "org3",
|
||||
prjgit: "oorg/foo.bar#point",
|
||||
res: [3]string{"oorg", "foo.bar", "point"},
|
||||
},
|
||||
{
|
||||
name: "whitespace shouldn't matter",
|
||||
prjgit: " oorg / \nfoo.bar\t # point ",
|
||||
res: [3]string{"oorg", "foo.bar", "point"},
|
||||
},
|
||||
{
|
||||
name: "repo org and empty branch",
|
||||
org: "org3",
|
||||
prjgit: "oorg/foo.bar#",
|
||||
res: [3]string{"oorg", "foo.bar", "master"},
|
||||
},
|
||||
{
|
||||
name: "only branch defined",
|
||||
org: "org3",
|
||||
prjgit: "#mybranch",
|
||||
res: [3]string{"org3", "_ObsPrj", "mybranch"},
|
||||
},
|
||||
{
|
||||
name: "only org and branch defined",
|
||||
org: "org3",
|
||||
prjgit: "org1/#mybranch",
|
||||
res: [3]string{"org1", "_ObsPrj", "mybranch"},
|
||||
},
|
||||
{
|
||||
name: "empty org and repo",
|
||||
org: "org3",
|
||||
prjgit: "/repo#",
|
||||
res: [3]string{"org3", "repo", "master"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
c := &common.AutogitConfig{
|
||||
Organization: test.org,
|
||||
Branch: test.branch,
|
||||
GitProjectName: test.prjgit,
|
||||
}
|
||||
|
||||
i, j, k := c.GetPrjGit()
|
||||
res := []string{i, j, k}
|
||||
if !slices.Equal(res, test.res[:]) {
|
||||
t.Error("Expected", test.res, "but received", res)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -33,3 +33,6 @@ const (
|
||||
|
||||
TopicApp = "src"
|
||||
)
|
||||
|
||||
// when set, pushing to remote does not happen, and other remote side-effects should also not happen
|
||||
var IsDryRun bool
|
||||
|
||||
@@ -24,10 +24,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@@ -43,12 +44,20 @@ type GitStatusLister interface {
|
||||
GitStatus(cwd string) ([]GitStatusData, error)
|
||||
}
|
||||
|
||||
type GitDiffLister interface {
|
||||
GitDiff(cwd, base, head string) (string, error)
|
||||
}
|
||||
|
||||
type Git interface {
|
||||
// error if git, but wrong remote
|
||||
GitClone(repo, branch, remoteUrl string) (string, error) // clone, or check if path is already checked out remote and force pulls, error otherwise. Return remotename, errror
|
||||
|
||||
GitParseCommits(cwd string, commitIDs []string) (parsedCommits []GitCommit, err error)
|
||||
GitCatFile(cwd, commitId, filename string) (data []byte, err error)
|
||||
GetPath() string
|
||||
|
||||
GitBranchHead(gitDir, branchName string) (string, error)
|
||||
GitRemoteHead(gitDir, remoteName, branchName string) (string, error)
|
||||
io.Closer
|
||||
|
||||
GitSubmoduleLister
|
||||
@@ -58,14 +67,16 @@ type Git interface {
|
||||
GitExecOrPanic(cwd string, params ...string)
|
||||
GitExec(cwd string, params ...string) error
|
||||
GitExecWithOutput(cwd string, params ...string) (string, error)
|
||||
|
||||
GitDiffLister
|
||||
}
|
||||
|
||||
type GitHandlerImpl struct {
|
||||
DebugLogger bool
|
||||
|
||||
GitPath string
|
||||
GitCommiter string
|
||||
GitEmail string
|
||||
|
||||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
func (s *GitHandlerImpl) GetPath() string {
|
||||
@@ -73,34 +84,88 @@ func (s *GitHandlerImpl) GetPath() string {
|
||||
}
|
||||
|
||||
type GitHandlerGenerator interface {
|
||||
CreateGitHandler(git_author, email, prjName string) (Git, error)
|
||||
ReadExistingPath(git_author, email, gitPath string) (Git, error)
|
||||
CreateGitHandler(org string) (Git, error)
|
||||
ReadExistingPath(org string) (Git, error)
|
||||
|
||||
ReleaseLock(path string)
|
||||
}
|
||||
|
||||
type GitHandlerGeneratorImpl struct{}
|
||||
type gitHandlerGeneratorImpl struct {
|
||||
path string
|
||||
git_author string
|
||||
email string
|
||||
|
||||
func (s *GitHandlerGeneratorImpl) CreateGitHandler(git_author, email, prj_name string) (Git, error) {
|
||||
gitPath, err := os.MkdirTemp("", prj_name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Cannot create temp dir: %w", err)
|
||||
}
|
||||
|
||||
if err = os.Chmod(gitPath, 0700); err != nil {
|
||||
return nil, fmt.Errorf("Cannot fix permissions of temp dir: %w", err)
|
||||
}
|
||||
|
||||
return s.ReadExistingPath(git_author, email, gitPath)
|
||||
lock_lock sync.Mutex
|
||||
lock map[string]*sync.Mutex // per org
|
||||
}
|
||||
|
||||
func (*GitHandlerGeneratorImpl) ReadExistingPath(git_author, email, gitPath string) (Git, error) {
|
||||
func AllocateGitWorkTree(basePath, gitAuthor, email string) (*gitHandlerGeneratorImpl, error) {
|
||||
if fi, err := os.Stat(basePath); err != nil || !fi.IsDir() {
|
||||
return nil, fmt.Errorf("Git basepath not a valid directory: %s %w", basePath, err)
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(basePath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(basePath, 0o700); err != nil {
|
||||
return nil, fmt.Errorf("Cannot create git directory structure: %s: %w", basePath, err)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("Error checking git directory strcture: %s: %w", basePath, err)
|
||||
}
|
||||
} else if !fi.IsDir() {
|
||||
return nil, fmt.Errorf("Invalid git directory structure: %s != directory", basePath)
|
||||
}
|
||||
|
||||
return &gitHandlerGeneratorImpl{
|
||||
path: basePath,
|
||||
git_author: gitAuthor,
|
||||
email: email,
|
||||
|
||||
lock: make(map[string]*sync.Mutex),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *gitHandlerGeneratorImpl) CreateGitHandler(org string) (Git, error) {
|
||||
path := path.Join(s.path, org)
|
||||
if fs, err := os.Stat(path); (err != nil && !os.IsNotExist(err)) || (err == nil && !fs.IsDir()) {
|
||||
return nil, err
|
||||
} else if err != nil && os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(path, 0o777); err != nil && !os.IsExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return s.ReadExistingPath(org)
|
||||
}
|
||||
|
||||
func (s *gitHandlerGeneratorImpl) ReadExistingPath(org string) (Git, error) {
|
||||
LogDebug("Locking git org:", org)
|
||||
s.lock_lock.Lock()
|
||||
defer s.lock_lock.Unlock()
|
||||
|
||||
if _, ok := s.lock[org]; !ok {
|
||||
s.lock[org] = &sync.Mutex{}
|
||||
}
|
||||
s.lock[org].Lock()
|
||||
|
||||
git := &GitHandlerImpl{
|
||||
GitCommiter: git_author,
|
||||
GitPath: gitPath,
|
||||
GitCommiter: s.git_author,
|
||||
GitEmail: s.email,
|
||||
GitPath: path.Join(s.path, org),
|
||||
lock: s.lock[org],
|
||||
}
|
||||
|
||||
return git, nil
|
||||
}
|
||||
|
||||
func (s *gitHandlerGeneratorImpl) ReleaseLock(org string) {
|
||||
m, ok := s.lock[org]
|
||||
if ok {
|
||||
LogDebug("Unlocking git org:", org)
|
||||
m.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
//func (h *GitHandler) ProcessBranchList() []string {
|
||||
// if h.HasError() {
|
||||
// return make([]string, 0)
|
||||
@@ -139,20 +204,96 @@ func (refs *GitReferences) addReference(id, branch string) {
|
||||
refs.refs = append(refs.refs, GitReference{Branch: branch, Id: id})
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitBranchHead(gitDir, branchName string) (string, error) {
|
||||
id, err := e.GitExecWithOutput(gitDir, "rev-list", "-1", branchName)
|
||||
func (e *GitHandlerImpl) GitClone(repo, branch, remoteUrl string) (string, error) {
|
||||
LogDebug("Cloning", remoteUrl, " repo:", repo, " branch:", branch)
|
||||
remoteUrlComp, err := ParseGitRemoteUrl(remoteUrl)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Can't find default remote branch: %s", branchName)
|
||||
return "", fmt.Errorf("Cannot parse remote URL: %w", err)
|
||||
}
|
||||
remoteBranch := "HEAD"
|
||||
if len(branch) == 0 && remoteUrlComp != nil {
|
||||
branch = remoteUrlComp.Commit
|
||||
remoteBranch = branch
|
||||
} else if len(branch) > 0 {
|
||||
remoteBranch = branch
|
||||
}
|
||||
remoteName := remoteUrlComp.RemoteName()
|
||||
if remoteUrlComp != nil {
|
||||
LogDebug("Clone", *remoteUrlComp, " -> ", remoteName)
|
||||
} else {
|
||||
LogDebug("Clone", "[default] -> ", remoteName)
|
||||
}
|
||||
|
||||
remoteRef := remoteName + "/" + remoteBranch
|
||||
if fi, err := os.Stat(path.Join(e.GitPath, repo)); os.IsNotExist(err) {
|
||||
if err = e.GitExec("", "clone", "--origin", remoteName, remoteUrl, repo); err != nil {
|
||||
return remoteName, err
|
||||
}
|
||||
} else if err != nil || !fi.IsDir() {
|
||||
return remoteName, fmt.Errorf("Clone location not a directory or Stat error: %w", err)
|
||||
} else {
|
||||
if u, err := e.GitExecWithOutput(repo, "remote", "get-url", remoteName); err != nil {
|
||||
e.GitExecOrPanic(repo, "remote", "add", remoteName, remoteUrl)
|
||||
} else if clonedRemote := strings.TrimSpace(u); clonedRemote != remoteUrl {
|
||||
e.GitExecOrPanic(repo, "remote", "set-url", remoteName, remoteUrl)
|
||||
}
|
||||
|
||||
// check if we have submodule to deinit
|
||||
if list, _ := e.GitSubmoduleList(repo, "HEAD"); len(list) > 0 {
|
||||
e.GitExecOrPanic(repo, "submodule", "deinit", "--all", "--force")
|
||||
}
|
||||
|
||||
e.GitExecOrPanic(repo, "fetch", "--prune", remoteName, remoteBranch)
|
||||
}
|
||||
|
||||
refsBytes, err := os.ReadFile(path.Join(e.GitPath, repo, ".git/refs/remotes", remoteName, "HEAD"))
|
||||
if err != nil {
|
||||
LogError("Cannot read HEAD of remote", remoteName)
|
||||
return remoteName, fmt.Errorf("Cannot read HEAD of remote %s", remoteName)
|
||||
}
|
||||
|
||||
refs := string(refsBytes)
|
||||
if refs[0:5] != "ref: " {
|
||||
LogError("Unexpected format of remote HEAD ref:", refs)
|
||||
return remoteName, fmt.Errorf("Unexpected format of remote HEAD ref: %s", refs)
|
||||
}
|
||||
|
||||
if len(branch) == 0 || branch == "HEAD" {
|
||||
remoteRef = strings.TrimSpace(refs[5:])
|
||||
branch = remoteRef[strings.LastIndex(remoteRef, "/")+1:]
|
||||
LogDebug("remoteRef", remoteRef)
|
||||
LogDebug("branch", branch)
|
||||
}
|
||||
|
||||
args := []string{"fetch", "--prune", remoteName, branch}
|
||||
if strings.TrimSpace(e.GitExecWithOutputOrPanic(repo, "rev-parse", "--is-shallow-repository")) == "true" {
|
||||
args = slices.Insert(args, 1, "--unshallow")
|
||||
}
|
||||
e.GitExecOrPanic(repo, args...)
|
||||
return remoteName, e.GitExec(repo, "checkout", "--track", "-B", branch, remoteRef)
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitBranchHead(gitDir, branchName string) (string, error) {
|
||||
id, err := e.GitExecWithOutput(gitDir, "show-ref", "--hash", "--verify", "refs/heads/"+branchName)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Can't find default branch: %s", branchName)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(id), nil
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitRemoteHead(gitDir, remote, branchName string) (string, error) {
|
||||
id, err := e.GitExecWithOutput(gitDir, "show-ref", "--hash", "--verify", "refs/remotes/"+remote+"/"+branchName)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Can't find default branch: %s", branchName)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(id), nil
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) Close() error {
|
||||
if err := os.RemoveAll(e.GitPath); err != nil {
|
||||
return err
|
||||
}
|
||||
e.GitPath = ""
|
||||
LogDebug("Unlocking git lock")
|
||||
e.lock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -175,14 +316,16 @@ func (h writeFunc) Close() error {
|
||||
func (e *GitHandlerImpl) GitExecWithOutputOrPanic(cwd string, params ...string) string {
|
||||
out, err := e.GitExecWithOutput(cwd, params...)
|
||||
if err != nil {
|
||||
log.Panicln("git command failed:", params, "@", cwd, "err:", err)
|
||||
LogError("git command failed:", params, "@", cwd, "err:", err)
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitExecOrPanic(cwd string, params ...string) {
|
||||
if err := e.GitExec(cwd, params...); err != nil {
|
||||
log.Panicln("git command failed:", params, "@", cwd, "err:", err)
|
||||
LogError("git command failed:", params, "@", cwd, "err:", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,17 +353,11 @@ func (e *GitHandlerImpl) GitExecWithOutput(cwd string, params ...string) (string
|
||||
cmd.Dir = filepath.Join(e.GitPath, cwd)
|
||||
cmd.Stdin = nil
|
||||
|
||||
if e.DebugLogger {
|
||||
log.Printf("git execute: %#v\n", cmd.Args)
|
||||
}
|
||||
LogDebug("git execute @", cwd, ":", cmd.Args)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if e.DebugLogger {
|
||||
log.Println(string(out))
|
||||
}
|
||||
LogDebug(string(out))
|
||||
if err != nil {
|
||||
if e.DebugLogger {
|
||||
log.Printf(" *** error: %v\n", err)
|
||||
}
|
||||
LogError("git", cmd.Args, " error:", err)
|
||||
return "", fmt.Errorf("error executing: git %#v \n%s\n err: %w", cmd.Args, out, err)
|
||||
}
|
||||
|
||||
@@ -356,21 +493,29 @@ func parseGitMsg(data <-chan byte) (GitMsg, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseGitCommitHdr(data <-chan byte) ([2]string, error) {
|
||||
func parseGitCommitHdr(oldHdr [2]string, data <-chan byte) ([2]string, int, error) {
|
||||
hdr := make([]byte, 0, 60)
|
||||
val := make([]byte, 0, 1000)
|
||||
|
||||
c := <-data
|
||||
size := 1
|
||||
if c != '\n' { // end of header marker
|
||||
for ; c != ' '; c = <-data {
|
||||
hdr = append(hdr, c)
|
||||
size++
|
||||
}
|
||||
if size == 1 { // continuation header here
|
||||
hdr = []byte(oldHdr[0])
|
||||
val = append([]byte(oldHdr[1]), '\n')
|
||||
}
|
||||
for c := <-data; c != '\n'; c = <-data {
|
||||
val = append(val, c)
|
||||
size++
|
||||
}
|
||||
size++
|
||||
}
|
||||
|
||||
return [2]string{string(hdr), string(val)}, nil
|
||||
return [2]string{string(hdr), string(val)}, size, nil
|
||||
}
|
||||
|
||||
func parseGitCommitMsg(data <-chan byte, l int) (string, error) {
|
||||
@@ -380,7 +525,6 @@ func parseGitCommitMsg(data <-chan byte, l int) (string, error) {
|
||||
msg = append(msg, c)
|
||||
l--
|
||||
}
|
||||
// l--
|
||||
|
||||
if l != 0 {
|
||||
return "", fmt.Errorf("Unexpected data in the git commit msg: l=%d", l)
|
||||
@@ -400,12 +544,14 @@ func parseGitCommit(data <-chan byte) (GitCommit, error) {
|
||||
var c GitCommit
|
||||
l := hdr.size
|
||||
for {
|
||||
hdr, err := parseGitCommitHdr(data)
|
||||
var hdr [2]string
|
||||
hdr, size, err := parseGitCommitHdr(hdr, data)
|
||||
if err != nil {
|
||||
return GitCommit{}, nil
|
||||
}
|
||||
l -= size
|
||||
|
||||
if len(hdr[0])+len(hdr[1]) == 0 { // hdr end marker
|
||||
if size == 1 {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -413,10 +559,7 @@ func parseGitCommit(data <-chan byte) (GitCommit, error) {
|
||||
case "tree":
|
||||
c.Tree = hdr[1]
|
||||
}
|
||||
|
||||
l -= len(hdr[0]) + len(hdr[1]) + 2
|
||||
}
|
||||
l--
|
||||
|
||||
c.Msg, err = parseGitCommitMsg(data, l)
|
||||
return c, err
|
||||
@@ -453,7 +596,6 @@ func parseTreeEntry(data <-chan byte, hashLen int) (GitTreeEntry, error) {
|
||||
}
|
||||
|
||||
func parseGitTree(data <-chan byte) (GitTree, error) {
|
||||
|
||||
hdr, err := parseGitMsg(data)
|
||||
if err != nil {
|
||||
return GitTree{}, err
|
||||
@@ -506,7 +648,7 @@ func (e *GitHandlerImpl) GitParseCommits(cwd string, commitIDs []string) (parsed
|
||||
var done sync.Mutex
|
||||
|
||||
done.Lock()
|
||||
data_in, data_out := ChanIO{make(chan byte, 256)}, ChanIO{make(chan byte, 70)}
|
||||
data_in, data_out := ChanIO{make(chan byte)}, ChanIO{make(chan byte)}
|
||||
parsedCommits = make([]GitCommit, 0, len(commitIDs))
|
||||
|
||||
go func() {
|
||||
@@ -536,15 +678,16 @@ func (e *GitHandlerImpl) GitParseCommits(cwd string, commitIDs []string) (parsed
|
||||
cmd.Stdout = &data_in
|
||||
cmd.Stdin = &data_out
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
if e.DebugLogger {
|
||||
log.Println(string(data))
|
||||
}
|
||||
LogError(string(data))
|
||||
return len(data), nil
|
||||
})
|
||||
if e.DebugLogger {
|
||||
log.Printf("command run: %v\n", cmd.Args)
|
||||
LogDebug("command run:", cmd.Args)
|
||||
if e := cmd.Run(); e != nil {
|
||||
LogError(e)
|
||||
close(data_in.ch)
|
||||
close(data_out.ch)
|
||||
return nil, e
|
||||
}
|
||||
err = cmd.Run()
|
||||
|
||||
done.Lock()
|
||||
return
|
||||
@@ -555,7 +698,7 @@ func (e *GitHandlerImpl) GitCatFile(cwd, commitId, filename string) (data []byte
|
||||
var done sync.Mutex
|
||||
|
||||
done.Lock()
|
||||
data_in, data_out := ChanIO{make(chan byte, 256)}, ChanIO{make(chan byte, 70)}
|
||||
data_in, data_out := ChanIO{make(chan byte)}, ChanIO{make(chan byte)}
|
||||
|
||||
go func() {
|
||||
defer done.Unlock()
|
||||
@@ -563,24 +706,27 @@ func (e *GitHandlerImpl) GitCatFile(cwd, commitId, filename string) (data []byte
|
||||
|
||||
data_out.Write([]byte(commitId))
|
||||
data_out.ch <- '\x00'
|
||||
c, err := parseGitCommit(data_in.ch)
|
||||
|
||||
var c GitCommit
|
||||
c, err = parseGitCommit(data_in.ch)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing git commit: %v\n", err)
|
||||
LogError("Error parsing git commit:", err)
|
||||
return
|
||||
}
|
||||
data_out.Write([]byte(c.Tree))
|
||||
data_out.ch <- '\x00'
|
||||
tree, err := parseGitTree(data_in.ch)
|
||||
|
||||
var tree GitTree
|
||||
tree, err = parseGitTree(data_in.ch)
|
||||
|
||||
if err != nil {
|
||||
if e.DebugLogger {
|
||||
log.Printf("Error parsing git tree: %v\n", err)
|
||||
}
|
||||
LogError("Error parsing git tree:", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, te := range tree.items {
|
||||
if te.isBlob() && te.name == filename {
|
||||
LogInfo("blob", te.hash)
|
||||
data_out.Write([]byte(te.hash))
|
||||
data_out.ch <- '\x00'
|
||||
data, err = parseGitBlob(data_in.ch)
|
||||
@@ -588,7 +734,7 @@ func (e *GitHandlerImpl) GitCatFile(cwd, commitId, filename string) (data []byte
|
||||
}
|
||||
}
|
||||
|
||||
err = fmt.Errorf("file not found: '%s'", filename)
|
||||
LogError("file not found:", filename)
|
||||
}()
|
||||
|
||||
cmd := exec.Command("/usr/bin/git", "cat-file", "--batch", "-Z")
|
||||
@@ -601,28 +747,29 @@ func (e *GitHandlerImpl) GitCatFile(cwd, commitId, filename string) (data []byte
|
||||
cmd.Stdout = &data_in
|
||||
cmd.Stdin = &data_out
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
if e.DebugLogger {
|
||||
log.Println(string(data))
|
||||
}
|
||||
LogError(string(data))
|
||||
return len(data), nil
|
||||
})
|
||||
if e.DebugLogger {
|
||||
log.Printf("command run: %v\n", cmd.Args)
|
||||
LogDebug("command run:", cmd.Args)
|
||||
if e := cmd.Run(); e != nil {
|
||||
LogError(e)
|
||||
close(data_in.ch)
|
||||
close(data_out.ch)
|
||||
return nil, e
|
||||
}
|
||||
err = cmd.Run()
|
||||
|
||||
done.Lock()
|
||||
return
|
||||
}
|
||||
|
||||
// return (filename) -> (hash) map for all submodules
|
||||
// TODO: recursive? map different orgs, not just assume '.' for path
|
||||
func (e *GitHandlerImpl) GitSubmoduleList(gitPath, commitId string) (submoduleList map[string]string, err error) {
|
||||
var done sync.Mutex
|
||||
submoduleList = make(map[string]string)
|
||||
|
||||
done.Lock()
|
||||
data_in, data_out := ChanIO{make(chan byte, 256)}, ChanIO{make(chan byte, 70)}
|
||||
data_in, data_out := ChanIO{make(chan byte)}, ChanIO{make(chan byte)}
|
||||
|
||||
LogDebug("Getting submodules for:", commitId)
|
||||
|
||||
go func() {
|
||||
defer done.Unlock()
|
||||
@@ -636,19 +783,32 @@ func (e *GitHandlerImpl) GitSubmoduleList(gitPath, commitId string) (submoduleLi
|
||||
err = fmt.Errorf("Error parsing git commit. Err: %w", err)
|
||||
return
|
||||
}
|
||||
data_out.Write([]byte(c.Tree))
|
||||
data_out.ch <- '\x00'
|
||||
var tree GitTree
|
||||
tree, err = parseGitTree(data_in.ch)
|
||||
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error parsing git tree: %w", err)
|
||||
return
|
||||
}
|
||||
trees := make(map[string]string)
|
||||
trees[""] = c.Tree
|
||||
|
||||
for _, te := range tree.items {
|
||||
if te.isSubmodule() {
|
||||
submoduleList[te.name] = te.hash
|
||||
for len(trees) > 0 {
|
||||
for p, tree := range trees {
|
||||
delete(trees, p)
|
||||
|
||||
data_out.Write([]byte(tree))
|
||||
data_out.ch <- '\x00'
|
||||
var tree GitTree
|
||||
tree, err = parseGitTree(data_in.ch)
|
||||
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error parsing git tree: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, te := range tree.items {
|
||||
if te.isTree() {
|
||||
trees[p+te.name+"/"] = te.hash
|
||||
} else if te.isSubmodule() {
|
||||
submoduleList[p+te.name] = te.hash
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -663,34 +823,32 @@ func (e *GitHandlerImpl) GitSubmoduleList(gitPath, commitId string) (submoduleLi
|
||||
cmd.Stdout = &data_in
|
||||
cmd.Stdin = &data_out
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
if e.DebugLogger {
|
||||
log.Println(string(data))
|
||||
}
|
||||
LogError(string(data))
|
||||
return len(data), nil
|
||||
})
|
||||
if e.DebugLogger {
|
||||
log.Printf("command run: %v\n", cmd.Args)
|
||||
LogDebug("command run:", cmd.Args)
|
||||
if e := cmd.Run(); e != nil {
|
||||
LogError(e)
|
||||
close(data_in.ch)
|
||||
close(data_out.ch)
|
||||
return submoduleList, e
|
||||
}
|
||||
err = cmd.Run()
|
||||
|
||||
done.Lock()
|
||||
return submoduleList, err
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitSubmoduleCommitId(cwd, packageName, commitId string) (subCommitId string, valid bool) {
|
||||
data_in, data_out := ChanIO{make(chan byte, 256)}, ChanIO{make(chan byte, 70)}
|
||||
data_in, data_out := ChanIO{make(chan byte)}, ChanIO{make(chan byte)}
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
if e.DebugLogger {
|
||||
log.Printf("getting commit id '%s' from git at '%s' with packageName: %s\n", commitId, cwd, packageName)
|
||||
}
|
||||
LogDebug("getting commit id", commitId, "from git at", cwd, "with packageName:", packageName)
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
subCommitId = "wrong"
|
||||
subCommitId = ""
|
||||
commitId = "ok"
|
||||
valid = false
|
||||
}
|
||||
@@ -703,14 +861,16 @@ func (e *GitHandlerImpl) GitSubmoduleCommitId(cwd, packageName, commitId string)
|
||||
data_out.ch <- '\x00'
|
||||
c, err := parseGitCommit(data_in.ch)
|
||||
if err != nil {
|
||||
log.Panicf("Error parsing git commit: %v\n", err)
|
||||
LogError("Error parsing git commit:", err)
|
||||
panic(err)
|
||||
}
|
||||
data_out.Write([]byte(c.Tree))
|
||||
data_out.ch <- '\x00'
|
||||
tree, err := parseGitTree(data_in.ch)
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Error parsing git tree: %v\n", err)
|
||||
LogError("Error parsing git tree:", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, te := range tree.items {
|
||||
@@ -731,18 +891,19 @@ func (e *GitHandlerImpl) GitSubmoduleCommitId(cwd, packageName, commitId string)
|
||||
cmd.Stdout = &data_in
|
||||
cmd.Stdin = &data_out
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
log.Println(string(data))
|
||||
LogError(string(data))
|
||||
return len(data), nil
|
||||
})
|
||||
if e.DebugLogger {
|
||||
log.Printf("command run: %v\n", cmd.Args)
|
||||
}
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Printf("Error running command %v, err: %v", cmd.Args, err)
|
||||
LogDebug("command run:", cmd.Args)
|
||||
if e := cmd.Run(); e != nil {
|
||||
LogError(e)
|
||||
close(data_in.ch)
|
||||
close(data_out.ch)
|
||||
return subCommitId, false
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return subCommitId, len(subCommitId) == len(commitId)
|
||||
return subCommitId, len(subCommitId) > 0
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -757,6 +918,16 @@ type GitStatusData struct {
|
||||
Path string
|
||||
Status int
|
||||
States [3]string
|
||||
|
||||
/*
|
||||
<sub> A 4 character field describing the submodule state.
|
||||
"N..." when the entry is not a submodule.
|
||||
"S<c><m><u>" when the entry is a submodule.
|
||||
<c> is "C" if the commit changed; otherwise ".".
|
||||
<m> is "M" if it has tracked changes; otherwise ".".
|
||||
<u> is "U" if there are untracked changes; otherwise ".".
|
||||
*/
|
||||
SubmoduleChanges string
|
||||
}
|
||||
|
||||
func parseGitStatusHexString(data io.ByteReader) (string, error) {
|
||||
@@ -779,6 +950,20 @@ func parseGitStatusHexString(data io.ByteReader) (string, error) {
|
||||
}
|
||||
}
|
||||
func parseGitStatusString(data io.ByteReader) (string, error) {
|
||||
str := make([]byte, 0, 100)
|
||||
for {
|
||||
c, err := data.ReadByte()
|
||||
if err != nil {
|
||||
return "", errors.New("Unexpected EOF. Expected NUL string term")
|
||||
}
|
||||
if c == 0 || c == ' ' {
|
||||
return string(str), nil
|
||||
}
|
||||
str = append(str, c)
|
||||
}
|
||||
}
|
||||
|
||||
func parseGitStatusStringWithSpace(data io.ByteReader) (string, error) {
|
||||
str := make([]byte, 0, 100)
|
||||
for {
|
||||
c, err := data.ReadByte()
|
||||
@@ -819,7 +1004,7 @@ func parseSingleStatusEntry(data io.ByteReader) (*GitStatusData, error) {
|
||||
return nil, err
|
||||
}
|
||||
ret.Status = GitStatus_Modified
|
||||
ret.Path, err = parseGitStatusString(data)
|
||||
ret.Path, err = parseGitStatusStringWithSpace(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -829,11 +1014,11 @@ func parseSingleStatusEntry(data io.ByteReader) (*GitStatusData, error) {
|
||||
return nil, err
|
||||
}
|
||||
ret.Status = GitStatus_Renamed
|
||||
ret.Path, err = parseGitStatusString(data)
|
||||
ret.Path, err = parseGitStatusStringWithSpace(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret.States[0], err = parseGitStatusString(data)
|
||||
ret.States[0], err = parseGitStatusStringWithSpace(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -843,7 +1028,7 @@ func parseSingleStatusEntry(data io.ByteReader) (*GitStatusData, error) {
|
||||
return nil, err
|
||||
}
|
||||
ret.Status = GitStatus_Untracked
|
||||
ret.Path, err = parseGitStatusString(data)
|
||||
ret.Path, err = parseGitStatusStringWithSpace(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -853,15 +1038,22 @@ func parseSingleStatusEntry(data io.ByteReader) (*GitStatusData, error) {
|
||||
return nil, err
|
||||
}
|
||||
ret.Status = GitStatus_Ignored
|
||||
ret.Path, err = parseGitStatusString(data)
|
||||
ret.Path, err = parseGitStatusStringWithSpace(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case 'u':
|
||||
var err error
|
||||
if err = skipGitStatusEntry(data, 7); err != nil {
|
||||
if err = skipGitStatusEntry(data, 2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ret.SubmoduleChanges, err = parseGitStatusString(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = skipGitStatusEntry(data, 4); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ret.States[0], err = parseGitStatusHexString(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -872,7 +1064,7 @@ func parseSingleStatusEntry(data io.ByteReader) (*GitStatusData, error) {
|
||||
return nil, err
|
||||
}
|
||||
ret.Status = GitStatus_Unmerged
|
||||
ret.Path, err = parseGitStatusString(data)
|
||||
ret.Path, err = parseGitStatusStringWithSpace(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -898,9 +1090,7 @@ func parseGitStatusData(data io.ByteReader) ([]GitStatusData, error) {
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitStatus(cwd string) (ret []GitStatusData, err error) {
|
||||
if e.DebugLogger {
|
||||
log.Println("getting git-status()")
|
||||
}
|
||||
LogDebug("getting git-status()")
|
||||
|
||||
cmd := exec.Command("/usr/bin/git", "status", "--porcelain=2", "-z")
|
||||
cmd.Env = []string{
|
||||
@@ -910,16 +1100,37 @@ func (e *GitHandlerImpl) GitStatus(cwd string) (ret []GitStatusData, err error)
|
||||
}
|
||||
cmd.Dir = filepath.Join(e.GitPath, cwd)
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
log.Println(string(data))
|
||||
LogError(string(data))
|
||||
return len(data), nil
|
||||
})
|
||||
if e.DebugLogger {
|
||||
log.Printf("command run: %v\n", cmd.Args)
|
||||
}
|
||||
LogDebug("command run:", cmd.Args)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Printf("Error running command %v, err: %v", cmd.Args, err)
|
||||
LogError("Error running command", cmd.Args, err)
|
||||
}
|
||||
|
||||
return parseGitStatusData(bufio.NewReader(bytes.NewReader(out)))
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitDiff(cwd, base, head string) (string, error) {
|
||||
LogDebug("getting diff from", base, "..", head)
|
||||
|
||||
cmd := exec.Command("/usr/bin/git", "diff", base+".."+head)
|
||||
cmd.Env = []string{
|
||||
"GIT_CEILING_DIRECTORIES=" + e.GitPath,
|
||||
"GIT_LFS_SKIP_SMUDGE=1",
|
||||
"GIT_CONFIG_GLOBAL=/dev/null",
|
||||
}
|
||||
cmd.Dir = filepath.Join(e.GitPath, cwd)
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
LogError(string(data))
|
||||
return len(data), nil
|
||||
})
|
||||
LogDebug("command run:", cmd.Args)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
LogError("Error running command", cmd.Args, err)
|
||||
}
|
||||
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
@@ -29,6 +29,70 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGitClone(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
repo string
|
||||
branch string
|
||||
remoteName string
|
||||
remoteUrl string
|
||||
}{
|
||||
{
|
||||
name: "Basic clone",
|
||||
repo: "pkgAclone",
|
||||
branch: "main",
|
||||
remoteName: "pkgA_main",
|
||||
remoteUrl: "/pkgA",
|
||||
},
|
||||
{
|
||||
name: "Remote branch is non-existent",
|
||||
repo: "pkgAclone",
|
||||
branch: "main_not_here",
|
||||
remoteName: "pkgA_main",
|
||||
remoteUrl: "/pkgA",
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
execPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := t.TempDir()
|
||||
os.Chdir(d)
|
||||
defer os.Chdir(execPath)
|
||||
cmd := exec.Command(path.Join(execPath, "test_clone_setup.sh"))
|
||||
if _, err := cmd.Output(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gh, err := AllocateGitWorkTree(d, "Test", "test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
g, err := gh.CreateGitHandler("org")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := g.GitClone(test.repo, test.branch, "file://"+d+test.remoteUrl); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
id, err := g.GitBranchHead(test.repo, test.branch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Fatal(id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGitMsgParsing(t *testing.T) {
|
||||
t.Run("tree message with size 56", func(t *testing.T) {
|
||||
const hdr = "f40888ea4515fe2e8eea617a16f5f50a45f652d894de3ad181d58de3aafb8f98 tree 56\x00"
|
||||
@@ -136,7 +200,7 @@ committer Adam Majer <amajer@suse.com> 1720709149 +0200
|
||||
})
|
||||
|
||||
t.Run("parse multiline headers", func(t *testing.T) {
|
||||
const commitData = "cae5831ab48470ff060a5aaa12eb6e5a7acaf91e commit 1491\x00" +
|
||||
const commitData = "cae5831ab48470ff060a5aaa12eb6e5a7acaf91e commit 1492\000" +
|
||||
`tree 1f9c8fe8099615d6d3921528402ac53f09213b02
|
||||
parent e08a654fae0ecc91678819e0b62a2e014bad3339
|
||||
author Yagiz Nizipli <yagiz@nizipli.com> 1720967314 -0400
|
||||
@@ -168,7 +232,7 @@ Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
|
||||
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
|
||||
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
|
||||
Reviewed-By: Richard Lau <rlau@redhat.com>
|
||||
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>` + "\x00"
|
||||
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>` + "\000"
|
||||
|
||||
ch := make(chan byte, 5000)
|
||||
for _, b := range []byte(commitData) {
|
||||
@@ -189,6 +253,51 @@ Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>` + "\x00"
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("parse multiline headers", func(t *testing.T) {
|
||||
const commitData = "c07c52c57a10fb355956df3caad2986613838f149274fbe312ad76560764829d commit 1150\000" + `tree 3e06b280ea056141ed5e8af9794a41ae5281930c45321803eab53a240cb60044
|
||||
parent 19362a2cecb1fd25a89e03611d08ac68dcb1732f9dc0a68a40926356787fa4ca
|
||||
author Adrian Schröter <adrian@suse.de> 1746600403 +0200
|
||||
committer Adrian Schröter <adrian@suse.de> 1746600403 +0200
|
||||
gpgsig-sha256 -----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQIzBAABCgAdFiEE1QF1zm/pNbvyhgLFkY2MlUwI22cFAmgbAd0ACgkQkY2MlUwI
|
||||
22dxtA//eUCzIqxVdaEnOrFeTyxKig/mCOjaAyctmwr0vXUyElRtjXe4TzVG3QtR
|
||||
uDfhIrKYLZ2tU/0TewTW/4XopWxLuqEzVQLrjuYl7K5P3GoYk52W1yGT0szzm7/i
|
||||
87j4UdRL9YGU/gYO7nSzstcfTP6AcmYzVUoOnwYR0K2vyOVjO4niL3mFXxLkIgIt
|
||||
jd82xcE4JpQz9Yjyq2nDdz4A55kLAwsqY+dOct4oC6bZmj1/JeoGQfPvUsvsQgcI
|
||||
syCHVh0GBxjvSv50V/VPzxQTFMal/TdtvAD4kmP/9RDi/5THzus8Peam8pV0gEIC
|
||||
Q15ZcuLwIsC9i7ifUDYgzLgBBRdpSI0qji4Y6clWULPVjsyghgyfQw1trBSySpC8
|
||||
O1XfajUM+rXyrBLP6kzY+zl/zyzRdJ8JhljmC+SmNuyyEB77Hkn83k0f+aBhhqC2
|
||||
4b3fIsKtwJZ1w6gr6SSz1BottiT9ShQzRaL8iRoF/2l5MkHPR+QFg2J7EIBqCbCQ
|
||||
hFUjdvWAXQBWkkTQlJmLmJBXDOLQg3o6xCbnZM0gPFjZWE7e3Mpky7H0+xPnoeg9
|
||||
ukuvkexXQ6yrdiekA7HRLc76Te/I0m7KDOOWZ3rbJV6uH/3ps4FbLQTZO12AtZ6J
|
||||
n8hYdYfw9yjCxiKUjnEtXtDRe8DJpqv+hO0Wj4MI5gIA2JE2lzY=
|
||||
=Keg5
|
||||
-----END PGP SIGNATURE-----
|
||||
|
||||
dummy change, don't merge
|
||||
` + "\000"
|
||||
ch := make(chan byte)
|
||||
go func() {
|
||||
for _, b := range []byte(commitData) {
|
||||
ch <- b
|
||||
}
|
||||
}()
|
||||
commit, err := parseGitCommit(ch)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if commit.Tree != "3e06b280ea056141ed5e8af9794a41ae5281930c45321803eab53a240cb60044" {
|
||||
t.Errorf("Invalid commit object: %#v", commit)
|
||||
}
|
||||
|
||||
if commit.Msg != "dummy change, don't merge\n" {
|
||||
t.Errorf("Invalid commit msg: '%s'", commit.Msg)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("parse tree object", func(t *testing.T) {
|
||||
const treeData = "\x31\x61\x30\x35\x64\x62\x37\x33\x36\x39\x33\x37\x34\x33\x30\x65\x31\x38\x64\x66\x34\x33\x61\x32\x37\x61\x39\x38\x30\x30\x31\x30\x31\x32\x65\x31\x65\x64\x32\x30\x34\x38\x32\x39\x38\x36\x37\x31\x32\x38\x66\x32\x63\x65\x38\x34\x30\x36\x62\x35\x63\x66\x63\x39\x20\x74\x72\x65\x65\x20\x32\x30\x35\x00\x34\x30\x30\x30\x30\x20\x62\x6f\x74\x73\x2d\x63\x6f\x6d\x6d\x6f\x6e\x00\x93\x17\xaa\x47\xf6\xea\x37\xe8\xbc\xe2\x80\x77\x57\x90\xf4\xa8\x01\xd7\xe3\x70\x2f\x84\xfb\xe1\xb0\x0e\x4a\x2c\x1c\x75\x2c\x2b\x34\x30\x30\x30\x30\x20\x6f\x62\x73\x2d\x73\x74\x61\x67\x69\x6e\x67\x2d\x62\x6f\x74\x00\x79\x77\x8b\x28\x7d\x37\x10\x59\xb9\x71\x28\x36\xed\x20\x31\x5f\xfb\xe1\xed\xb5\xba\x4f\x5e\xbb\x65\x65\x68\x23\x77\x32\x58\xfe\x34\x30\x30\x30\x30\x20\x70\x72\x2d\x72\x65\x76\x69\x65\x77\x00\x36\x0d\x45\xcb\x76\xb8\x93\xb3\x21\xba\xfa\xd5\x00\x9d\xfc\x59\xab\x88\xc1\x3c\x81\xcb\x48\x5a\xe0\x29\x29\x0f\xe3\x6b\x3c\x5e\x34\x30\x30\x30\x30\x20\x70\x72\x6a\x67\x69\x74\x2d\x75\x70\x64\x61\x74\x65\x72\x00\xb4\x0b\x1c\xf5\xfb\xec\x9a\xb2\x9f\x48\x3e\x21\x18\x0d\x51\xb7\x98\x6e\x21\x99\x74\x84\x67\x71\x41\x24\x42\xfc\xc9\x04\x12\x99\x00"
|
||||
|
||||
@@ -243,9 +352,36 @@ Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>` + "\x00"
|
||||
t.Error("expected submodule not found")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("parse nested trees with subtrees", func(t *testing.T) {
|
||||
const data = "873a323b262ebb3bd77b2592b2e11bdd08dbc721cbf4ac9f97637e58e1fffce7 tree 1083\x00100644\x20\x2Egitattributes\x00\xD8v\xA95\x87\xC1\xA9\xFCPn\xDD\xD4\x13\x9B\x8E\xD2\xCFs\xBD\x11q\x8A\xAE\x8A\x7Cg\xE2C\x14J\x01\xB0100644\x20\x2Egitignore\x00\xC3\xCD\x8En\x887\x3AJ\xA0P\xEEL\xD4\xF5\xD2v\x9C\xA6v\xC5D\x60\x40\x95\xD1\x0B\xA4\xB8\x86\xD4rE100644\x20COPYING\x00\x12\x2A\x28\xC8\xB9\x5D\x9B\x8A\x23\x1F\xE96\x07\x3F\xA9D\x90\xFD\xCE\x2Bi\x2D\x031\x5C\xCC\xC4fx\x00\xC22100644\x20README\x2Emd\x00\x92D\xF7\xFF\x0E0\x5C\xF2\xAC\x0DA\x06\x92\x0B\xD6z\x3CGh\x00y\x7EW1\xB9a\x8Ch\x215Fa100644\x20_service\x00\xC51\xF2\x12\xF3\x24\x9C\xD9\x9F\x0A\x93Mp\x12\xC1\xF7i\x05\x95\xC5Z\x06\x95i\x3Az\xC3\xF59\x7E\xF8\x1B100644\x20autogits\x2Echanges\x00\xF7\x8D\xBF\x0A\xCB\x5D\xB7y\x8C\xA9\x9C\xEB\x92\xAFd\x2C\x98\x23\x0C\x13\x13\xED\xDE\x5D\xBALD6\x3BR\x5B\xCA100644\x20autogits\x2Espec\x00\xD2\xBC\x20v\xD3\xE5F\xCA\xEE\xEA\x18\xC84\x0D\xA7\xCA\xD8O\xF2\x0A\xAB\x40\x2A\xFAL\x3B\xB4\xE6\x11\xE7o\xD140000\x20common\x00\xE2\xC9dg\xD0\x5D\xD1\xF1\x8ARW\xF0\x96\xD6\x29\x2F\x8F\xD9\xC7\x82\x1A\xB7\xAAw\xB0\xCE\xA8\xFE\xC8\xD7D\xF2100755\x20dev_test_helper\x2Esh\x00\xECY\xDD\xB3rz\x9Fh\xD4\x2E\x85\x02\x13\xF8\xFE\xB57\x8B\x1B6\x8E\x09dC\x1E\xE0\x90\x09\x08\xED\xBD_40000\x20devel\x2Dimporter\x00v\x98\x9B\x92\xD8\x24lu\xFC\xB2d\xC9\xCENb\xEE\x0F\x21\x8B\x92\x88\xDBs\xF8\x2E\xA8\xC8W\x1C\x20\xCF\xD440000\x20doc\x00\x8Akyq\xD0\xCF\xB8\x2F\x80Y\x2F\x11\xF0\x14\xA9\xFE\x96\x14\xE0W\x2C\xCF\xB9\x86\x7E\xFDi\xD7\x1F\x08Q\xFB40000\x20gitea\x2Devents\x2Drabbitmq\x2Dpublisher\x00\x5Cb\x3Fh\xA2\x06\x06\x0Cd\x09\xA5\xD9\xF7\x23\x5C\xF85\xF5\xB8\xBE\x7F\xD4O\x25t\xEF\xCC\xAB\x18\x7C\x0C\xF3100644\x20go\x2Emod\x00j\x85\x0B\x03\xC8\x9F\x9F\x0F\xC8\xE0\x8C\xF7\x3D\xC19\xF7\x12gk\xD6\x18JN\x24\xC0\x1C\xBE\x97oY\x02\x8D100644\x20go\x2Esum\x00h\x88\x2E\x27\xED\xD39\x8D\x12\x0F\x7D\x97\xA2\x5DE\xB9\x82o\x0Cu\xF4l\xA17s\x28\x2BQT\xE6\x12\x9040000\x20group\x2Dreview\x00\x7E\x7B\xB42\x0F\x3B\xC9o\x2C\xE79\x1DR\xE2\xE4i\xAE\xF6u\x90\x09\xD8\xC9c\xE7\xF7\xC7\x92\xFB\xD7\xDD140000\x20obs\x2Dstaging\x2Dbot\x00\x12\xE8\xAF\x09\xD4\x5D\x13\x8D\xC9\x0AvPDc\xB6\x7C\xAC4\xD9\xC5\xD4_\x98i\xBE2\xA7\x25aj\xE2k40000\x20obs\x2Dstatus\x2Dservice\x00MATY\xA3\xFA\xED\x05\xBE\xEB\x2B\x07\x9CN\xA9\xF3SB\x22MlV\xA4\x5D\xDA\x0B\x0F\x23\xA1\xA8z\xD740000\x20systemd\x00\x2D\xE2\x03\x7E\xBD\xEB6\x8F\xC5\x0E\x12\xD4\xBD\x97P\xDD\xA2\x92\xCE6n\x08Q\xCA\xE4\x15\x97\x8F\x26V\x3DW100644\x20vendor\x2Etar\x2Ezst\x00\xD9\x2Es\x03I\x91\x22\x24\xC86q\x91\x95\xEF\xA3\xC9\x3C\x06D\x90w\xAD\xCB\xAE\xEEu2i\xCE\x05\x09u40000\x20workflow\x2Ddirect\x00\x94\xDB\xDFc\xB5A\xD5\x16\xB3\xC3ng\x94J\xE7\x101jYF\x15Q\xE97\xCFg\x14\x12\x28\x3A\xFC\xDB40000\x20workflow\x2Dpr\x00\xC1\xD8Z9\x18\x60\xA2\xE2\xEF\xB0\xFC\xD7\x2Ah\xF07\x0D\xEC\x8A7\x7E\x1A\xAAn\x13\x9C\xEC\x05s\xE8\xBDf\x00"
|
||||
|
||||
ch := make(chan byte, 2000)
|
||||
for _, b := range []byte(data) {
|
||||
ch <- b
|
||||
}
|
||||
|
||||
tree, err := parseGitTree(ch)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, item := range tree.items {
|
||||
t.Log(item)
|
||||
if item.name == "workflow-pr" && item.hash == "c1d85a391860a2e2efb0fcd72a68f0370dec8a377e1aaa6e139cec0573e8bd66" && item.isTree() {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Error("expected submodule not found")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCommitTreeParsingOfHead(t *testing.T) {
|
||||
func TestCommitTreeParsing(t *testing.T) {
|
||||
gitDir := t.TempDir()
|
||||
testDir, _ := os.Getwd()
|
||||
var commitId string
|
||||
@@ -260,11 +396,58 @@ func TestCommitTreeParsingOfHead(t *testing.T) {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
gh, err := AllocateGitWorkTree(gitDir, "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Run("GitCatFile commit", func(t *testing.T) {
|
||||
h, _ := gh.ReadExistingPath(".")
|
||||
defer h.Close()
|
||||
|
||||
file, err := h.GitCatFile("", commitId, "help")
|
||||
if err != nil {
|
||||
t.Error("failed", err)
|
||||
}
|
||||
|
||||
if string(file) != "help\n" {
|
||||
t.Error("expected 'help\\n' but got", string(file))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("GitCatFile commit", func(t *testing.T) {
|
||||
h, _ := gh.ReadExistingPath(".")
|
||||
defer h.Close()
|
||||
|
||||
file, err := h.GitCatFile("", "HEAD", "help")
|
||||
if err != nil {
|
||||
t.Error("failed", err)
|
||||
}
|
||||
|
||||
if string(file) != "help\n" {
|
||||
t.Error("expected 'help\\n' but got", string(file))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("GitCatFile bad commit", func(t *testing.T) {
|
||||
h, _ := gh.ReadExistingPath(".")
|
||||
defer h.Close()
|
||||
|
||||
file, err := h.GitCatFile("", "518b468f391bf01d5d76d497d7cbecfa8b46d185714cf8745800ae18afb21afd", "help")
|
||||
if err == nil {
|
||||
t.Error("expected error, but not nothing")
|
||||
}
|
||||
|
||||
if string(file) != "" {
|
||||
t.Error("expected 'help\\n' but got", file)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("reads HEAD and parses the tree", func(t *testing.T) {
|
||||
const nodejs21 = "c678c57007d496a98bec668ae38f2c26a695f94af78012f15d044ccf066ccb41"
|
||||
h := GitHandlerImpl{
|
||||
GitPath: gitDir,
|
||||
}
|
||||
h, _ := gh.ReadExistingPath(".")
|
||||
defer h.Close()
|
||||
|
||||
id, ok := h.GitSubmoduleCommitId("", "nodejs21", commitId)
|
||||
if !ok {
|
||||
t.Error("failed parse")
|
||||
@@ -275,9 +458,9 @@ func TestCommitTreeParsingOfHead(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("reads README.md", func(t *testing.T) {
|
||||
h := GitHandlerImpl{
|
||||
GitPath: gitDir,
|
||||
}
|
||||
h, _ := gh.ReadExistingPath(".")
|
||||
defer h.Close()
|
||||
|
||||
data, err := h.GitCatFile("", commitId, "README.md")
|
||||
if err != nil {
|
||||
t.Errorf("failed parse: %v", err)
|
||||
@@ -288,9 +471,8 @@ func TestCommitTreeParsingOfHead(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("read HEAD", func(t *testing.T) {
|
||||
h := GitHandlerImpl{
|
||||
GitPath: gitDir,
|
||||
}
|
||||
h, _ := gh.ReadExistingPath(".")
|
||||
defer h.Close()
|
||||
|
||||
data, err := h.GitSubmoduleList("", "HEAD")
|
||||
if err != nil {
|
||||
@@ -373,6 +555,8 @@ func TestGitStatusParse(t *testing.T) {
|
||||
Path: ".gitmodules",
|
||||
Status: GitStatus_Unmerged,
|
||||
States: [3]string{"587ec403f01113f2629da538f6e14b84781f70ac59c41aeedd978ea8b1253a76", "d23eb05d9ca92883ab9f4d28f3ec90c05f667f3a5c8c8e291bd65e03bac9ae3c", "087b1d5f22dbf0aa4a879fff27fff03568b334c90daa5f2653f4a7961e24ea33"},
|
||||
|
||||
SubmoduleChanges: "N...",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -380,14 +564,13 @@ func TestGitStatusParse(t *testing.T) {
|
||||
name: "Renamed file",
|
||||
data: []byte("1 M. N... 100644 100644 100644 d23eb05d9ca92883ab9f4d28f3ec90c05f667f3a5c8c8e291bd65e03bac9ae3c 896cd09f36d39e782d66ae32dd5614d4f4d83fc689f132aab2dfc019a9f5b6f3 .gitmodules\x002 R. S... 160000 160000 160000 3befe051a34612530acfa84c736d2454278453ec0f78ec028f25d2980f8c3559 3befe051a34612530acfa84c736d2454278453ec0f78ec028f25d2980f8c3559 R100 pkgQ\x00pkgC\x00"),
|
||||
res: []GitStatusData{
|
||||
{
|
||||
Path: "pkgQ",
|
||||
{
|
||||
Path: "pkgQ",
|
||||
Status: GitStatus_Renamed,
|
||||
States: [3]string{"pkgC"},
|
||||
|
||||
},
|
||||
{
|
||||
Path: ".gitmodules",
|
||||
{
|
||||
Path: ".gitmodules",
|
||||
Status: GitStatus_Modified,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -36,6 +36,12 @@ func (o *IssueEditIssueAttachmentReader) ReadResponse(response runtime.ClientRes
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewIssueEditIssueAttachmentUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 423:
|
||||
result := NewIssueEditIssueAttachmentLocked()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
@@ -189,6 +195,78 @@ func (o *IssueEditIssueAttachmentNotFound) readResponse(response runtime.ClientR
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewIssueEditIssueAttachmentUnprocessableEntity creates a IssueEditIssueAttachmentUnprocessableEntity with default headers values
|
||||
func NewIssueEditIssueAttachmentUnprocessableEntity() *IssueEditIssueAttachmentUnprocessableEntity {
|
||||
return &IssueEditIssueAttachmentUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
IssueEditIssueAttachmentUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type IssueEditIssueAttachmentUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this issue edit issue attachment unprocessable entity response has a 2xx status code
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this issue edit issue attachment unprocessable entity response has a 3xx status code
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this issue edit issue attachment unprocessable entity response has a 4xx status code
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this issue edit issue attachment unprocessable entity response has a 5xx status code
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this issue edit issue attachment unprocessable entity response a status code equal to that given
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the issue edit issue attachment unprocessable entity response
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/issues/{index}/assets/{attachment_id}][%d] issueEditIssueAttachmentUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/issues/{index}/assets/{attachment_id}][%d] issueEditIssueAttachmentUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *IssueEditIssueAttachmentUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewIssueEditIssueAttachmentLocked creates a IssueEditIssueAttachmentLocked with default headers values
|
||||
func NewIssueEditIssueAttachmentLocked() *IssueEditIssueAttachmentLocked {
|
||||
return &IssueEditIssueAttachmentLocked{}
|
||||
|
||||
@@ -36,6 +36,12 @@ func (o *IssueEditIssueCommentAttachmentReader) ReadResponse(response runtime.Cl
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewIssueEditIssueCommentAttachmentUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 423:
|
||||
result := NewIssueEditIssueCommentAttachmentLocked()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
@@ -189,6 +195,78 @@ func (o *IssueEditIssueCommentAttachmentNotFound) readResponse(response runtime.
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewIssueEditIssueCommentAttachmentUnprocessableEntity creates a IssueEditIssueCommentAttachmentUnprocessableEntity with default headers values
|
||||
func NewIssueEditIssueCommentAttachmentUnprocessableEntity() *IssueEditIssueCommentAttachmentUnprocessableEntity {
|
||||
return &IssueEditIssueCommentAttachmentUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
IssueEditIssueCommentAttachmentUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type IssueEditIssueCommentAttachmentUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this issue edit issue comment attachment unprocessable entity response has a 2xx status code
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this issue edit issue comment attachment unprocessable entity response has a 3xx status code
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this issue edit issue comment attachment unprocessable entity response has a 4xx status code
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this issue edit issue comment attachment unprocessable entity response has a 5xx status code
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this issue edit issue comment attachment unprocessable entity response a status code equal to that given
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the issue edit issue comment attachment unprocessable entity response
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/issues/comments/{id}/assets/{attachment_id}][%d] issueEditIssueCommentAttachmentUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/issues/comments/{id}/assets/{attachment_id}][%d] issueEditIssueCommentAttachmentUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *IssueEditIssueCommentAttachmentUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewIssueEditIssueCommentAttachmentLocked creates a IssueEditIssueCommentAttachmentLocked with default headers values
|
||||
func NewIssueEditIssueCommentAttachmentLocked() *IssueEditIssueCommentAttachmentLocked {
|
||||
return &IssueEditIssueCommentAttachmentLocked{}
|
||||
|
||||
@@ -64,13 +64,13 @@ type IssueSearchIssuesParams struct {
|
||||
|
||||
/* Assigned.
|
||||
|
||||
filter (issues / pulls) assigned to you, default is false
|
||||
Filter issues or pulls assigned to the authenticated user
|
||||
*/
|
||||
Assigned *bool
|
||||
|
||||
/* Before.
|
||||
|
||||
Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
|
||||
Only show issues updated before the given time (RFC 3339 format)
|
||||
|
||||
Format: date-time
|
||||
*/
|
||||
@@ -78,49 +78,51 @@ type IssueSearchIssuesParams struct {
|
||||
|
||||
/* Created.
|
||||
|
||||
filter (issues / pulls) created by you, default is false
|
||||
Filter issues or pulls created by the authenticated user
|
||||
*/
|
||||
Created *bool
|
||||
|
||||
/* Labels.
|
||||
|
||||
comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
|
||||
Comma-separated list of label names. Fetch only issues that have any of these labels. Non existent labels are discarded.
|
||||
*/
|
||||
Labels *string
|
||||
|
||||
/* Limit.
|
||||
|
||||
page size of results
|
||||
Number of items per page
|
||||
*/
|
||||
Limit *int64
|
||||
|
||||
/* Mentioned.
|
||||
|
||||
filter (issues / pulls) mentioning you, default is false
|
||||
Filter issues or pulls mentioning the authenticated user
|
||||
*/
|
||||
Mentioned *bool
|
||||
|
||||
/* Milestones.
|
||||
|
||||
comma separated list of milestone names. Fetch only issues that have any of this milestones. Non existent are discarded
|
||||
Comma-separated list of milestone names. Fetch only issues that have any of these milestones. Non existent milestones are discarded.
|
||||
*/
|
||||
Milestones *string
|
||||
|
||||
/* Owner.
|
||||
|
||||
filter by owner
|
||||
Filter by repository owner
|
||||
*/
|
||||
Owner *string
|
||||
|
||||
/* Page.
|
||||
|
||||
page number of results to return (1-based)
|
||||
Page number of results to return (1-based)
|
||||
|
||||
Default: 1
|
||||
*/
|
||||
Page *int64
|
||||
|
||||
/* PriorityRepoID.
|
||||
|
||||
repository to prioritize in the results
|
||||
Repository ID to prioritize in the results
|
||||
|
||||
Format: int64
|
||||
*/
|
||||
@@ -128,25 +130,25 @@ type IssueSearchIssuesParams struct {
|
||||
|
||||
/* Q.
|
||||
|
||||
search string
|
||||
Search string
|
||||
*/
|
||||
Q *string
|
||||
|
||||
/* ReviewRequested.
|
||||
|
||||
filter pulls requesting your review, default is false
|
||||
Filter pull requests where the authenticated user's review was requested
|
||||
*/
|
||||
ReviewRequested *bool
|
||||
|
||||
/* Reviewed.
|
||||
|
||||
filter pulls reviewed by you, default is false
|
||||
Filter pull requests reviewed by the authenticated user
|
||||
*/
|
||||
Reviewed *bool
|
||||
|
||||
/* Since.
|
||||
|
||||
Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
|
||||
Only show issues updated after the given time (RFC 3339 format)
|
||||
|
||||
Format: date-time
|
||||
*/
|
||||
@@ -154,19 +156,21 @@ type IssueSearchIssuesParams struct {
|
||||
|
||||
/* State.
|
||||
|
||||
whether issue is open or closed
|
||||
State of the issue
|
||||
|
||||
Default: "open"
|
||||
*/
|
||||
State *string
|
||||
|
||||
/* Team.
|
||||
|
||||
filter by team (requires organization owner parameter to be provided)
|
||||
Filter by team (requires organization owner parameter)
|
||||
*/
|
||||
Team *string
|
||||
|
||||
/* Type.
|
||||
|
||||
filter by type (issues / pulls) if set
|
||||
Filter by issue type
|
||||
*/
|
||||
Type *string
|
||||
|
||||
@@ -187,7 +191,36 @@ func (o *IssueSearchIssuesParams) WithDefaults() *IssueSearchIssuesParams {
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *IssueSearchIssuesParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
var (
|
||||
assignedDefault = bool(false)
|
||||
|
||||
createdDefault = bool(false)
|
||||
|
||||
mentionedDefault = bool(false)
|
||||
|
||||
pageDefault = int64(1)
|
||||
|
||||
reviewRequestedDefault = bool(false)
|
||||
|
||||
reviewedDefault = bool(false)
|
||||
|
||||
stateDefault = string("open")
|
||||
)
|
||||
|
||||
val := IssueSearchIssuesParams{
|
||||
Assigned: &assignedDefault,
|
||||
Created: &createdDefault,
|
||||
Mentioned: &mentionedDefault,
|
||||
Page: &pageDefault,
|
||||
ReviewRequested: &reviewRequestedDefault,
|
||||
Reviewed: &reviewedDefault,
|
||||
State: &stateDefault,
|
||||
}
|
||||
|
||||
val.timeout = o.timeout
|
||||
val.Context = o.Context
|
||||
val.HTTPClient = o.HTTPClient
|
||||
*o = val
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the issue search issues params
|
||||
|
||||
@@ -30,6 +30,18 @@ func (o *IssueSearchIssuesReader) ReadResponse(response runtime.ClientResponse,
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 400:
|
||||
result := NewIssueSearchIssuesBadRequest()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewIssueSearchIssuesUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/issues/search] issueSearchIssues", response, response.Code())
|
||||
}
|
||||
@@ -102,3 +114,147 @@ func (o *IssueSearchIssuesOK) readResponse(response runtime.ClientResponse, cons
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewIssueSearchIssuesBadRequest creates a IssueSearchIssuesBadRequest with default headers values
|
||||
func NewIssueSearchIssuesBadRequest() *IssueSearchIssuesBadRequest {
|
||||
return &IssueSearchIssuesBadRequest{}
|
||||
}
|
||||
|
||||
/*
|
||||
IssueSearchIssuesBadRequest describes a response with status code 400, with default header values.
|
||||
|
||||
APIError is error format response
|
||||
*/
|
||||
type IssueSearchIssuesBadRequest struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this issue search issues bad request response has a 2xx status code
|
||||
func (o *IssueSearchIssuesBadRequest) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this issue search issues bad request response has a 3xx status code
|
||||
func (o *IssueSearchIssuesBadRequest) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this issue search issues bad request response has a 4xx status code
|
||||
func (o *IssueSearchIssuesBadRequest) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this issue search issues bad request response has a 5xx status code
|
||||
func (o *IssueSearchIssuesBadRequest) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this issue search issues bad request response a status code equal to that given
|
||||
func (o *IssueSearchIssuesBadRequest) IsCode(code int) bool {
|
||||
return code == 400
|
||||
}
|
||||
|
||||
// Code gets the status code for the issue search issues bad request response
|
||||
func (o *IssueSearchIssuesBadRequest) Code() int {
|
||||
return 400
|
||||
}
|
||||
|
||||
func (o *IssueSearchIssuesBadRequest) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/issues/search][%d] issueSearchIssuesBadRequest", 400)
|
||||
}
|
||||
|
||||
func (o *IssueSearchIssuesBadRequest) String() string {
|
||||
return fmt.Sprintf("[GET /repos/issues/search][%d] issueSearchIssuesBadRequest", 400)
|
||||
}
|
||||
|
||||
func (o *IssueSearchIssuesBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewIssueSearchIssuesUnprocessableEntity creates a IssueSearchIssuesUnprocessableEntity with default headers values
|
||||
func NewIssueSearchIssuesUnprocessableEntity() *IssueSearchIssuesUnprocessableEntity {
|
||||
return &IssueSearchIssuesUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
IssueSearchIssuesUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type IssueSearchIssuesUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this issue search issues unprocessable entity response has a 2xx status code
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this issue search issues unprocessable entity response has a 3xx status code
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this issue search issues unprocessable entity response has a 4xx status code
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this issue search issues unprocessable entity response has a 5xx status code
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this issue search issues unprocessable entity response a status code equal to that given
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the issue search issues unprocessable entity response
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/issues/search][%d] issueSearchIssuesUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[GET /repos/issues/search][%d] issueSearchIssuesUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *IssueSearchIssuesUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// NewListActionTasksParams creates a new ListActionTasksParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewListActionTasksParams() *ListActionTasksParams {
|
||||
return &ListActionTasksParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewListActionTasksParamsWithTimeout creates a new ListActionTasksParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewListActionTasksParamsWithTimeout(timeout time.Duration) *ListActionTasksParams {
|
||||
return &ListActionTasksParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewListActionTasksParamsWithContext creates a new ListActionTasksParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewListActionTasksParamsWithContext(ctx context.Context) *ListActionTasksParams {
|
||||
return &ListActionTasksParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewListActionTasksParamsWithHTTPClient creates a new ListActionTasksParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewListActionTasksParamsWithHTTPClient(client *http.Client) *ListActionTasksParams {
|
||||
return &ListActionTasksParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the list action tasks operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type ListActionTasksParams struct {
|
||||
|
||||
/* Limit.
|
||||
|
||||
page size of results, default maximum page size is 50
|
||||
*/
|
||||
Limit *int64
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Page.
|
||||
|
||||
page number of results to return (1-based)
|
||||
*/
|
||||
Page *int64
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the list action tasks params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *ListActionTasksParams) WithDefaults() *ListActionTasksParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the list action tasks params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *ListActionTasksParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithTimeout(timeout time.Duration) *ListActionTasksParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithContext(ctx context.Context) *ListActionTasksParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithHTTPClient(client *http.Client) *ListActionTasksParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithLimit adds the limit to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithLimit(limit *int64) *ListActionTasksParams {
|
||||
o.SetLimit(limit)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetLimit adds the limit to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetLimit(limit *int64) {
|
||||
o.Limit = limit
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithOwner(owner string) *ListActionTasksParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithPage adds the page to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithPage(page *int64) *ListActionTasksParams {
|
||||
o.SetPage(page)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPage adds the page to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetPage(page *int64) {
|
||||
o.Page = page
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the list action tasks params
|
||||
func (o *ListActionTasksParams) WithRepo(repo string) *ListActionTasksParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the list action tasks params
|
||||
func (o *ListActionTasksParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *ListActionTasksParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
if o.Limit != nil {
|
||||
|
||||
// query param limit
|
||||
var qrLimit int64
|
||||
|
||||
if o.Limit != nil {
|
||||
qrLimit = *o.Limit
|
||||
}
|
||||
qLimit := swag.FormatInt64(qrLimit)
|
||||
if qLimit != "" {
|
||||
|
||||
if err := r.SetQueryParam("limit", qLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.Page != nil {
|
||||
|
||||
// query param page
|
||||
var qrPage int64
|
||||
|
||||
if o.Page != nil {
|
||||
qrPage = *o.Page
|
||||
}
|
||||
qPage := swag.FormatInt64(qrPage)
|
||||
if qPage != "" {
|
||||
|
||||
if err := r.SetQueryParam("page", qPage); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// ListActionTasksReader is a Reader for the ListActionTasks structure.
|
||||
type ListActionTasksReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *ListActionTasksReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewListActionTasksOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 400:
|
||||
result := NewListActionTasksBadRequest()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 403:
|
||||
result := NewListActionTasksForbidden()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 404:
|
||||
result := NewListActionTasksNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 409:
|
||||
result := NewListActionTasksConflict()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewListActionTasksUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/actions/tasks] ListActionTasks", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewListActionTasksOK creates a ListActionTasksOK with default headers values
|
||||
func NewListActionTasksOK() *ListActionTasksOK {
|
||||
return &ListActionTasksOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksOK describes a response with status code 200, with default header values.
|
||||
|
||||
TasksList
|
||||
*/
|
||||
type ListActionTasksOK struct {
|
||||
Payload *models.ActionTaskResponse
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this list action tasks o k response has a 2xx status code
|
||||
func (o *ListActionTasksOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this list action tasks o k response has a 3xx status code
|
||||
func (o *ListActionTasksOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this list action tasks o k response has a 4xx status code
|
||||
func (o *ListActionTasksOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this list action tasks o k response has a 5xx status code
|
||||
func (o *ListActionTasksOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this list action tasks o k response a status code equal to that given
|
||||
func (o *ListActionTasksOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the list action tasks o k response
|
||||
func (o *ListActionTasksOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *ListActionTasksOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksOK) GetPayload() *models.ActionTaskResponse {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *ListActionTasksOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.ActionTaskResponse)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewListActionTasksBadRequest creates a ListActionTasksBadRequest with default headers values
|
||||
func NewListActionTasksBadRequest() *ListActionTasksBadRequest {
|
||||
return &ListActionTasksBadRequest{}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksBadRequest describes a response with status code 400, with default header values.
|
||||
|
||||
APIError is error format response
|
||||
*/
|
||||
type ListActionTasksBadRequest struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this list action tasks bad request response has a 2xx status code
|
||||
func (o *ListActionTasksBadRequest) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this list action tasks bad request response has a 3xx status code
|
||||
func (o *ListActionTasksBadRequest) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this list action tasks bad request response has a 4xx status code
|
||||
func (o *ListActionTasksBadRequest) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this list action tasks bad request response has a 5xx status code
|
||||
func (o *ListActionTasksBadRequest) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this list action tasks bad request response a status code equal to that given
|
||||
func (o *ListActionTasksBadRequest) IsCode(code int) bool {
|
||||
return code == 400
|
||||
}
|
||||
|
||||
// Code gets the status code for the list action tasks bad request response
|
||||
func (o *ListActionTasksBadRequest) Code() int {
|
||||
return 400
|
||||
}
|
||||
|
||||
func (o *ListActionTasksBadRequest) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksBadRequest", 400)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksBadRequest) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksBadRequest", 400)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewListActionTasksForbidden creates a ListActionTasksForbidden with default headers values
|
||||
func NewListActionTasksForbidden() *ListActionTasksForbidden {
|
||||
return &ListActionTasksForbidden{}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksForbidden describes a response with status code 403, with default header values.
|
||||
|
||||
APIForbiddenError is a forbidden error response
|
||||
*/
|
||||
type ListActionTasksForbidden struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this list action tasks forbidden response has a 2xx status code
|
||||
func (o *ListActionTasksForbidden) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this list action tasks forbidden response has a 3xx status code
|
||||
func (o *ListActionTasksForbidden) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this list action tasks forbidden response has a 4xx status code
|
||||
func (o *ListActionTasksForbidden) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this list action tasks forbidden response has a 5xx status code
|
||||
func (o *ListActionTasksForbidden) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this list action tasks forbidden response a status code equal to that given
|
||||
func (o *ListActionTasksForbidden) IsCode(code int) bool {
|
||||
return code == 403
|
||||
}
|
||||
|
||||
// Code gets the status code for the list action tasks forbidden response
|
||||
func (o *ListActionTasksForbidden) Code() int {
|
||||
return 403
|
||||
}
|
||||
|
||||
func (o *ListActionTasksForbidden) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksForbidden", 403)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksForbidden) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksForbidden", 403)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewListActionTasksNotFound creates a ListActionTasksNotFound with default headers values
|
||||
func NewListActionTasksNotFound() *ListActionTasksNotFound {
|
||||
return &ListActionTasksNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type ListActionTasksNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this list action tasks not found response has a 2xx status code
|
||||
func (o *ListActionTasksNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this list action tasks not found response has a 3xx status code
|
||||
func (o *ListActionTasksNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this list action tasks not found response has a 4xx status code
|
||||
func (o *ListActionTasksNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this list action tasks not found response has a 5xx status code
|
||||
func (o *ListActionTasksNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this list action tasks not found response a status code equal to that given
|
||||
func (o *ListActionTasksNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the list action tasks not found response
|
||||
func (o *ListActionTasksNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *ListActionTasksNotFound) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksNotFound) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewListActionTasksConflict creates a ListActionTasksConflict with default headers values
|
||||
func NewListActionTasksConflict() *ListActionTasksConflict {
|
||||
return &ListActionTasksConflict{}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksConflict describes a response with status code 409, with default header values.
|
||||
|
||||
APIConflict is a conflict empty response
|
||||
*/
|
||||
type ListActionTasksConflict struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this list action tasks conflict response has a 2xx status code
|
||||
func (o *ListActionTasksConflict) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this list action tasks conflict response has a 3xx status code
|
||||
func (o *ListActionTasksConflict) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this list action tasks conflict response has a 4xx status code
|
||||
func (o *ListActionTasksConflict) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this list action tasks conflict response has a 5xx status code
|
||||
func (o *ListActionTasksConflict) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this list action tasks conflict response a status code equal to that given
|
||||
func (o *ListActionTasksConflict) IsCode(code int) bool {
|
||||
return code == 409
|
||||
}
|
||||
|
||||
// Code gets the status code for the list action tasks conflict response
|
||||
func (o *ListActionTasksConflict) Code() int {
|
||||
return 409
|
||||
}
|
||||
|
||||
func (o *ListActionTasksConflict) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksConflict", 409)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksConflict) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksConflict", 409)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksConflict) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewListActionTasksUnprocessableEntity creates a ListActionTasksUnprocessableEntity with default headers values
|
||||
func NewListActionTasksUnprocessableEntity() *ListActionTasksUnprocessableEntity {
|
||||
return &ListActionTasksUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasksUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type ListActionTasksUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this list action tasks unprocessable entity response has a 2xx status code
|
||||
func (o *ListActionTasksUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this list action tasks unprocessable entity response has a 3xx status code
|
||||
func (o *ListActionTasksUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this list action tasks unprocessable entity response has a 4xx status code
|
||||
func (o *ListActionTasksUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this list action tasks unprocessable entity response has a 5xx status code
|
||||
func (o *ListActionTasksUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this list action tasks unprocessable entity response a status code equal to that given
|
||||
func (o *ListActionTasksUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the list action tasks unprocessable entity response
|
||||
func (o *ListActionTasksUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *ListActionTasksUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/tasks][%d] listActionTasksUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *ListActionTasksUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// NewRepoCreateTagProtectionParams creates a new RepoCreateTagProtectionParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoCreateTagProtectionParams() *RepoCreateTagProtectionParams {
|
||||
return &RepoCreateTagProtectionParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionParamsWithTimeout creates a new RepoCreateTagProtectionParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoCreateTagProtectionParamsWithTimeout(timeout time.Duration) *RepoCreateTagProtectionParams {
|
||||
return &RepoCreateTagProtectionParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionParamsWithContext creates a new RepoCreateTagProtectionParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoCreateTagProtectionParamsWithContext(ctx context.Context) *RepoCreateTagProtectionParams {
|
||||
return &RepoCreateTagProtectionParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionParamsWithHTTPClient creates a new RepoCreateTagProtectionParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoCreateTagProtectionParamsWithHTTPClient(client *http.Client) *RepoCreateTagProtectionParams {
|
||||
return &RepoCreateTagProtectionParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtectionParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo create tag protection operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoCreateTagProtectionParams struct {
|
||||
|
||||
// Body.
|
||||
Body *models.CreateTagProtectionOption
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo create tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoCreateTagProtectionParams) WithDefaults() *RepoCreateTagProtectionParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo create tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoCreateTagProtectionParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) WithTimeout(timeout time.Duration) *RepoCreateTagProtectionParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) WithContext(ctx context.Context) *RepoCreateTagProtectionParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) WithHTTPClient(client *http.Client) *RepoCreateTagProtectionParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) WithBody(body *models.CreateTagProtectionOption) *RepoCreateTagProtectionParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) SetBody(body *models.CreateTagProtectionOption) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) WithOwner(owner string) *RepoCreateTagProtectionParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) WithRepo(repo string) *RepoCreateTagProtectionParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo create tag protection params
|
||||
func (o *RepoCreateTagProtectionParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoCreateTagProtectionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// RepoCreateTagProtectionReader is a Reader for the RepoCreateTagProtection structure.
|
||||
type RepoCreateTagProtectionReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoCreateTagProtectionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 201:
|
||||
result := NewRepoCreateTagProtectionCreated()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 403:
|
||||
result := NewRepoCreateTagProtectionForbidden()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 404:
|
||||
result := NewRepoCreateTagProtectionNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewRepoCreateTagProtectionUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 423:
|
||||
result := NewRepoCreateTagProtectionLocked()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[POST /repos/{owner}/{repo}/tag_protections] repoCreateTagProtection", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionCreated creates a RepoCreateTagProtectionCreated with default headers values
|
||||
func NewRepoCreateTagProtectionCreated() *RepoCreateTagProtectionCreated {
|
||||
return &RepoCreateTagProtectionCreated{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtectionCreated describes a response with status code 201, with default header values.
|
||||
|
||||
TagProtection
|
||||
*/
|
||||
type RepoCreateTagProtectionCreated struct {
|
||||
Payload *models.TagProtection
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo create tag protection created response has a 2xx status code
|
||||
func (o *RepoCreateTagProtectionCreated) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo create tag protection created response has a 3xx status code
|
||||
func (o *RepoCreateTagProtectionCreated) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo create tag protection created response has a 4xx status code
|
||||
func (o *RepoCreateTagProtectionCreated) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo create tag protection created response has a 5xx status code
|
||||
func (o *RepoCreateTagProtectionCreated) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo create tag protection created response a status code equal to that given
|
||||
func (o *RepoCreateTagProtectionCreated) IsCode(code int) bool {
|
||||
return code == 201
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo create tag protection created response
|
||||
func (o *RepoCreateTagProtectionCreated) Code() int {
|
||||
return 201
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionCreated) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionCreated %s", 201, payload)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionCreated) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionCreated %s", 201, payload)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionCreated) GetPayload() *models.TagProtection {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.TagProtection)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionForbidden creates a RepoCreateTagProtectionForbidden with default headers values
|
||||
func NewRepoCreateTagProtectionForbidden() *RepoCreateTagProtectionForbidden {
|
||||
return &RepoCreateTagProtectionForbidden{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtectionForbidden describes a response with status code 403, with default header values.
|
||||
|
||||
APIForbiddenError is a forbidden error response
|
||||
*/
|
||||
type RepoCreateTagProtectionForbidden struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo create tag protection forbidden response has a 2xx status code
|
||||
func (o *RepoCreateTagProtectionForbidden) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo create tag protection forbidden response has a 3xx status code
|
||||
func (o *RepoCreateTagProtectionForbidden) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo create tag protection forbidden response has a 4xx status code
|
||||
func (o *RepoCreateTagProtectionForbidden) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo create tag protection forbidden response has a 5xx status code
|
||||
func (o *RepoCreateTagProtectionForbidden) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo create tag protection forbidden response a status code equal to that given
|
||||
func (o *RepoCreateTagProtectionForbidden) IsCode(code int) bool {
|
||||
return code == 403
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo create tag protection forbidden response
|
||||
func (o *RepoCreateTagProtectionForbidden) Code() int {
|
||||
return 403
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionForbidden) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionForbidden", 403)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionForbidden) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionForbidden", 403)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionNotFound creates a RepoCreateTagProtectionNotFound with default headers values
|
||||
func NewRepoCreateTagProtectionNotFound() *RepoCreateTagProtectionNotFound {
|
||||
return &RepoCreateTagProtectionNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtectionNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoCreateTagProtectionNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo create tag protection not found response has a 2xx status code
|
||||
func (o *RepoCreateTagProtectionNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo create tag protection not found response has a 3xx status code
|
||||
func (o *RepoCreateTagProtectionNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo create tag protection not found response has a 4xx status code
|
||||
func (o *RepoCreateTagProtectionNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo create tag protection not found response has a 5xx status code
|
||||
func (o *RepoCreateTagProtectionNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo create tag protection not found response a status code equal to that given
|
||||
func (o *RepoCreateTagProtectionNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo create tag protection not found response
|
||||
func (o *RepoCreateTagProtectionNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionNotFound) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionNotFound) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionUnprocessableEntity creates a RepoCreateTagProtectionUnprocessableEntity with default headers values
|
||||
func NewRepoCreateTagProtectionUnprocessableEntity() *RepoCreateTagProtectionUnprocessableEntity {
|
||||
return &RepoCreateTagProtectionUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtectionUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type RepoCreateTagProtectionUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo create tag protection unprocessable entity response has a 2xx status code
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo create tag protection unprocessable entity response has a 3xx status code
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo create tag protection unprocessable entity response has a 4xx status code
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo create tag protection unprocessable entity response has a 5xx status code
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo create tag protection unprocessable entity response a status code equal to that given
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo create tag protection unprocessable entity response
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoCreateTagProtectionLocked creates a RepoCreateTagProtectionLocked with default headers values
|
||||
func NewRepoCreateTagProtectionLocked() *RepoCreateTagProtectionLocked {
|
||||
return &RepoCreateTagProtectionLocked{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtectionLocked describes a response with status code 423, with default header values.
|
||||
|
||||
APIRepoArchivedError is an error that is raised when an archived repo should be modified
|
||||
*/
|
||||
type RepoCreateTagProtectionLocked struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo create tag protection locked response has a 2xx status code
|
||||
func (o *RepoCreateTagProtectionLocked) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo create tag protection locked response has a 3xx status code
|
||||
func (o *RepoCreateTagProtectionLocked) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo create tag protection locked response has a 4xx status code
|
||||
func (o *RepoCreateTagProtectionLocked) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo create tag protection locked response has a 5xx status code
|
||||
func (o *RepoCreateTagProtectionLocked) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo create tag protection locked response a status code equal to that given
|
||||
func (o *RepoCreateTagProtectionLocked) IsCode(code int) bool {
|
||||
return code == 423
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo create tag protection locked response
|
||||
func (o *RepoCreateTagProtectionLocked) Code() int {
|
||||
return 423
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionLocked) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionLocked", 423)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionLocked) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/tag_protections][%d] repoCreateTagProtectionLocked", 423)
|
||||
}
|
||||
|
||||
func (o *RepoCreateTagProtectionLocked) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// NewRepoDeleteTagProtectionParams creates a new RepoDeleteTagProtectionParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoDeleteTagProtectionParams() *RepoDeleteTagProtectionParams {
|
||||
return &RepoDeleteTagProtectionParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoDeleteTagProtectionParamsWithTimeout creates a new RepoDeleteTagProtectionParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoDeleteTagProtectionParamsWithTimeout(timeout time.Duration) *RepoDeleteTagProtectionParams {
|
||||
return &RepoDeleteTagProtectionParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoDeleteTagProtectionParamsWithContext creates a new RepoDeleteTagProtectionParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoDeleteTagProtectionParamsWithContext(ctx context.Context) *RepoDeleteTagProtectionParams {
|
||||
return &RepoDeleteTagProtectionParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoDeleteTagProtectionParamsWithHTTPClient creates a new RepoDeleteTagProtectionParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoDeleteTagProtectionParamsWithHTTPClient(client *http.Client) *RepoDeleteTagProtectionParams {
|
||||
return &RepoDeleteTagProtectionParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoDeleteTagProtectionParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo delete tag protection operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoDeleteTagProtectionParams struct {
|
||||
|
||||
/* ID.
|
||||
|
||||
id of protected tag
|
||||
*/
|
||||
ID int64
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo delete tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoDeleteTagProtectionParams) WithDefaults() *RepoDeleteTagProtectionParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo delete tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoDeleteTagProtectionParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) WithTimeout(timeout time.Duration) *RepoDeleteTagProtectionParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) WithContext(ctx context.Context) *RepoDeleteTagProtectionParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) WithHTTPClient(client *http.Client) *RepoDeleteTagProtectionParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithID adds the id to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) WithID(id int64) *RepoDeleteTagProtectionParams {
|
||||
o.SetID(id)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetID adds the id to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) WithOwner(owner string) *RepoDeleteTagProtectionParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) WithRepo(repo string) *RepoDeleteTagProtectionParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo delete tag protection params
|
||||
func (o *RepoDeleteTagProtectionParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoDeleteTagProtectionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param id
|
||||
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// RepoDeleteTagProtectionReader is a Reader for the RepoDeleteTagProtection structure.
|
||||
type RepoDeleteTagProtectionReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoDeleteTagProtectionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 204:
|
||||
result := NewRepoDeleteTagProtectionNoContent()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewRepoDeleteTagProtectionNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[DELETE /repos/{owner}/{repo}/tag_protections/{id}] repoDeleteTagProtection", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoDeleteTagProtectionNoContent creates a RepoDeleteTagProtectionNoContent with default headers values
|
||||
func NewRepoDeleteTagProtectionNoContent() *RepoDeleteTagProtectionNoContent {
|
||||
return &RepoDeleteTagProtectionNoContent{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoDeleteTagProtectionNoContent describes a response with status code 204, with default header values.
|
||||
|
||||
APIEmpty is an empty response
|
||||
*/
|
||||
type RepoDeleteTagProtectionNoContent struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo delete tag protection no content response has a 2xx status code
|
||||
func (o *RepoDeleteTagProtectionNoContent) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo delete tag protection no content response has a 3xx status code
|
||||
func (o *RepoDeleteTagProtectionNoContent) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo delete tag protection no content response has a 4xx status code
|
||||
func (o *RepoDeleteTagProtectionNoContent) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo delete tag protection no content response has a 5xx status code
|
||||
func (o *RepoDeleteTagProtectionNoContent) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo delete tag protection no content response a status code equal to that given
|
||||
func (o *RepoDeleteTagProtectionNoContent) IsCode(code int) bool {
|
||||
return code == 204
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo delete tag protection no content response
|
||||
func (o *RepoDeleteTagProtectionNoContent) Code() int {
|
||||
return 204
|
||||
}
|
||||
|
||||
func (o *RepoDeleteTagProtectionNoContent) Error() string {
|
||||
return fmt.Sprintf("[DELETE /repos/{owner}/{repo}/tag_protections/{id}][%d] repoDeleteTagProtectionNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *RepoDeleteTagProtectionNoContent) String() string {
|
||||
return fmt.Sprintf("[DELETE /repos/{owner}/{repo}/tag_protections/{id}][%d] repoDeleteTagProtectionNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *RepoDeleteTagProtectionNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoDeleteTagProtectionNotFound creates a RepoDeleteTagProtectionNotFound with default headers values
|
||||
func NewRepoDeleteTagProtectionNotFound() *RepoDeleteTagProtectionNotFound {
|
||||
return &RepoDeleteTagProtectionNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoDeleteTagProtectionNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoDeleteTagProtectionNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo delete tag protection not found response has a 2xx status code
|
||||
func (o *RepoDeleteTagProtectionNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo delete tag protection not found response has a 3xx status code
|
||||
func (o *RepoDeleteTagProtectionNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo delete tag protection not found response has a 4xx status code
|
||||
func (o *RepoDeleteTagProtectionNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo delete tag protection not found response has a 5xx status code
|
||||
func (o *RepoDeleteTagProtectionNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo delete tag protection not found response a status code equal to that given
|
||||
func (o *RepoDeleteTagProtectionNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo delete tag protection not found response
|
||||
func (o *RepoDeleteTagProtectionNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoDeleteTagProtectionNotFound) Error() string {
|
||||
return fmt.Sprintf("[DELETE /repos/{owner}/{repo}/tag_protections/{id}][%d] repoDeleteTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoDeleteTagProtectionNotFound) String() string {
|
||||
return fmt.Sprintf("[DELETE /repos/{owner}/{repo}/tag_protections/{id}][%d] repoDeleteTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoDeleteTagProtectionNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -36,6 +36,12 @@ func (o *RepoEditReleaseAttachmentReader) ReadResponse(response runtime.ClientRe
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewRepoEditReleaseAttachmentUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[PATCH /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id}] repoEditReleaseAttachment", response, response.Code())
|
||||
}
|
||||
@@ -166,3 +172,75 @@ func (o *RepoEditReleaseAttachmentNotFound) readResponse(response runtime.Client
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoEditReleaseAttachmentUnprocessableEntity creates a RepoEditReleaseAttachmentUnprocessableEntity with default headers values
|
||||
func NewRepoEditReleaseAttachmentUnprocessableEntity() *RepoEditReleaseAttachmentUnprocessableEntity {
|
||||
return &RepoEditReleaseAttachmentUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditReleaseAttachmentUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type RepoEditReleaseAttachmentUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo edit release attachment unprocessable entity response has a 2xx status code
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo edit release attachment unprocessable entity response has a 3xx status code
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo edit release attachment unprocessable entity response has a 4xx status code
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo edit release attachment unprocessable entity response has a 5xx status code
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo edit release attachment unprocessable entity response a status code equal to that given
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo edit release attachment unprocessable entity response
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id}][%d] repoEditReleaseAttachmentUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id}][%d] repoEditReleaseAttachmentUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoEditReleaseAttachmentUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// NewRepoEditTagProtectionParams creates a new RepoEditTagProtectionParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoEditTagProtectionParams() *RepoEditTagProtectionParams {
|
||||
return &RepoEditTagProtectionParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionParamsWithTimeout creates a new RepoEditTagProtectionParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoEditTagProtectionParamsWithTimeout(timeout time.Duration) *RepoEditTagProtectionParams {
|
||||
return &RepoEditTagProtectionParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionParamsWithContext creates a new RepoEditTagProtectionParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoEditTagProtectionParamsWithContext(ctx context.Context) *RepoEditTagProtectionParams {
|
||||
return &RepoEditTagProtectionParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionParamsWithHTTPClient creates a new RepoEditTagProtectionParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoEditTagProtectionParamsWithHTTPClient(client *http.Client) *RepoEditTagProtectionParams {
|
||||
return &RepoEditTagProtectionParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditTagProtectionParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo edit tag protection operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoEditTagProtectionParams struct {
|
||||
|
||||
// Body.
|
||||
Body *models.EditTagProtectionOption
|
||||
|
||||
/* ID.
|
||||
|
||||
id of protected tag
|
||||
*/
|
||||
ID int64
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo edit tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoEditTagProtectionParams) WithDefaults() *RepoEditTagProtectionParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo edit tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoEditTagProtectionParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithTimeout(timeout time.Duration) *RepoEditTagProtectionParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithContext(ctx context.Context) *RepoEditTagProtectionParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithHTTPClient(client *http.Client) *RepoEditTagProtectionParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithBody(body *models.EditTagProtectionOption) *RepoEditTagProtectionParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetBody(body *models.EditTagProtectionOption) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithID adds the id to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithID(id int64) *RepoEditTagProtectionParams {
|
||||
o.SetID(id)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetID adds the id to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithOwner(owner string) *RepoEditTagProtectionParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) WithRepo(repo string) *RepoEditTagProtectionParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo edit tag protection params
|
||||
func (o *RepoEditTagProtectionParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoEditTagProtectionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// path param id
|
||||
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// RepoEditTagProtectionReader is a Reader for the RepoEditTagProtection structure.
|
||||
type RepoEditTagProtectionReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoEditTagProtectionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewRepoEditTagProtectionOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewRepoEditTagProtectionNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewRepoEditTagProtectionUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 423:
|
||||
result := NewRepoEditTagProtectionLocked()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[PATCH /repos/{owner}/{repo}/tag_protections/{id}] repoEditTagProtection", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionOK creates a RepoEditTagProtectionOK with default headers values
|
||||
func NewRepoEditTagProtectionOK() *RepoEditTagProtectionOK {
|
||||
return &RepoEditTagProtectionOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditTagProtectionOK describes a response with status code 200, with default header values.
|
||||
|
||||
TagProtection
|
||||
*/
|
||||
type RepoEditTagProtectionOK struct {
|
||||
Payload *models.TagProtection
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo edit tag protection o k response has a 2xx status code
|
||||
func (o *RepoEditTagProtectionOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo edit tag protection o k response has a 3xx status code
|
||||
func (o *RepoEditTagProtectionOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo edit tag protection o k response has a 4xx status code
|
||||
func (o *RepoEditTagProtectionOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo edit tag protection o k response has a 5xx status code
|
||||
func (o *RepoEditTagProtectionOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo edit tag protection o k response a status code equal to that given
|
||||
func (o *RepoEditTagProtectionOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo edit tag protection o k response
|
||||
func (o *RepoEditTagProtectionOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionOK) GetPayload() *models.TagProtection {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.TagProtection)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionNotFound creates a RepoEditTagProtectionNotFound with default headers values
|
||||
func NewRepoEditTagProtectionNotFound() *RepoEditTagProtectionNotFound {
|
||||
return &RepoEditTagProtectionNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditTagProtectionNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoEditTagProtectionNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo edit tag protection not found response has a 2xx status code
|
||||
func (o *RepoEditTagProtectionNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo edit tag protection not found response has a 3xx status code
|
||||
func (o *RepoEditTagProtectionNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo edit tag protection not found response has a 4xx status code
|
||||
func (o *RepoEditTagProtectionNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo edit tag protection not found response has a 5xx status code
|
||||
func (o *RepoEditTagProtectionNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo edit tag protection not found response a status code equal to that given
|
||||
func (o *RepoEditTagProtectionNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo edit tag protection not found response
|
||||
func (o *RepoEditTagProtectionNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionNotFound) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionNotFound) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionUnprocessableEntity creates a RepoEditTagProtectionUnprocessableEntity with default headers values
|
||||
func NewRepoEditTagProtectionUnprocessableEntity() *RepoEditTagProtectionUnprocessableEntity {
|
||||
return &RepoEditTagProtectionUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditTagProtectionUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type RepoEditTagProtectionUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo edit tag protection unprocessable entity response has a 2xx status code
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo edit tag protection unprocessable entity response has a 3xx status code
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo edit tag protection unprocessable entity response has a 4xx status code
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo edit tag protection unprocessable entity response has a 5xx status code
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo edit tag protection unprocessable entity response a status code equal to that given
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo edit tag protection unprocessable entity response
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoEditTagProtectionLocked creates a RepoEditTagProtectionLocked with default headers values
|
||||
func NewRepoEditTagProtectionLocked() *RepoEditTagProtectionLocked {
|
||||
return &RepoEditTagProtectionLocked{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditTagProtectionLocked describes a response with status code 423, with default header values.
|
||||
|
||||
APIRepoArchivedError is an error that is raised when an archived repo should be modified
|
||||
*/
|
||||
type RepoEditTagProtectionLocked struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo edit tag protection locked response has a 2xx status code
|
||||
func (o *RepoEditTagProtectionLocked) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo edit tag protection locked response has a 3xx status code
|
||||
func (o *RepoEditTagProtectionLocked) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo edit tag protection locked response has a 4xx status code
|
||||
func (o *RepoEditTagProtectionLocked) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo edit tag protection locked response has a 5xx status code
|
||||
func (o *RepoEditTagProtectionLocked) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo edit tag protection locked response a status code equal to that given
|
||||
func (o *RepoEditTagProtectionLocked) IsCode(code int) bool {
|
||||
return code == 423
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo edit tag protection locked response
|
||||
func (o *RepoEditTagProtectionLocked) Code() int {
|
||||
return 423
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionLocked) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionLocked", 423)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionLocked) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/tag_protections/{id}][%d] repoEditTagProtectionLocked", 423)
|
||||
}
|
||||
|
||||
func (o *RepoEditTagProtectionLocked) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewRepoGetLicensesParams creates a new RepoGetLicensesParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoGetLicensesParams() *RepoGetLicensesParams {
|
||||
return &RepoGetLicensesParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetLicensesParamsWithTimeout creates a new RepoGetLicensesParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoGetLicensesParamsWithTimeout(timeout time.Duration) *RepoGetLicensesParams {
|
||||
return &RepoGetLicensesParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetLicensesParamsWithContext creates a new RepoGetLicensesParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoGetLicensesParamsWithContext(ctx context.Context) *RepoGetLicensesParams {
|
||||
return &RepoGetLicensesParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetLicensesParamsWithHTTPClient creates a new RepoGetLicensesParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoGetLicensesParamsWithHTTPClient(client *http.Client) *RepoGetLicensesParams {
|
||||
return &RepoGetLicensesParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetLicensesParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo get licenses operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoGetLicensesParams struct {
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo get licenses params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoGetLicensesParams) WithDefaults() *RepoGetLicensesParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo get licenses params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoGetLicensesParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) WithTimeout(timeout time.Duration) *RepoGetLicensesParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) WithContext(ctx context.Context) *RepoGetLicensesParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) WithHTTPClient(client *http.Client) *RepoGetLicensesParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) WithOwner(owner string) *RepoGetLicensesParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) WithRepo(repo string) *RepoGetLicensesParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo get licenses params
|
||||
func (o *RepoGetLicensesParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoGetLicensesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// RepoGetLicensesReader is a Reader for the RepoGetLicenses structure.
|
||||
type RepoGetLicensesReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoGetLicensesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewRepoGetLicensesOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewRepoGetLicensesNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/licenses] repoGetLicenses", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetLicensesOK creates a RepoGetLicensesOK with default headers values
|
||||
func NewRepoGetLicensesOK() *RepoGetLicensesOK {
|
||||
return &RepoGetLicensesOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetLicensesOK describes a response with status code 200, with default header values.
|
||||
|
||||
LicensesList
|
||||
*/
|
||||
type RepoGetLicensesOK struct {
|
||||
Payload []string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo get licenses o k response has a 2xx status code
|
||||
func (o *RepoGetLicensesOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo get licenses o k response has a 3xx status code
|
||||
func (o *RepoGetLicensesOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo get licenses o k response has a 4xx status code
|
||||
func (o *RepoGetLicensesOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo get licenses o k response has a 5xx status code
|
||||
func (o *RepoGetLicensesOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo get licenses o k response a status code equal to that given
|
||||
func (o *RepoGetLicensesOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo get licenses o k response
|
||||
func (o *RepoGetLicensesOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/licenses][%d] repoGetLicensesOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/licenses][%d] repoGetLicensesOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesOK) GetPayload() []string {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoGetLicensesNotFound creates a RepoGetLicensesNotFound with default headers values
|
||||
func NewRepoGetLicensesNotFound() *RepoGetLicensesNotFound {
|
||||
return &RepoGetLicensesNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetLicensesNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoGetLicensesNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo get licenses not found response has a 2xx status code
|
||||
func (o *RepoGetLicensesNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo get licenses not found response has a 3xx status code
|
||||
func (o *RepoGetLicensesNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo get licenses not found response has a 4xx status code
|
||||
func (o *RepoGetLicensesNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo get licenses not found response has a 5xx status code
|
||||
func (o *RepoGetLicensesNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo get licenses not found response a status code equal to that given
|
||||
func (o *RepoGetLicensesNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo get licenses not found response
|
||||
func (o *RepoGetLicensesNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesNotFound) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/licenses][%d] repoGetLicensesNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesNotFound) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/licenses][%d] repoGetLicensesNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoGetLicensesNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -63,7 +63,7 @@ type RepoGetRawFileOrLFSParams struct {
|
||||
|
||||
/* Filepath.
|
||||
|
||||
filepath of the file to get
|
||||
path of the file to get, it should be "{ref}/{filepath}". If there is no ref could be inferred, it will be treated as the default branch
|
||||
*/
|
||||
Filepath string
|
||||
|
||||
@@ -75,7 +75,7 @@ type RepoGetRawFileOrLFSParams struct {
|
||||
|
||||
/* Ref.
|
||||
|
||||
The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
The name of the commit/branch/tag. Default the repository’s default branch
|
||||
*/
|
||||
Ref *string
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ type RepoGetRawFileParams struct {
|
||||
|
||||
/* Filepath.
|
||||
|
||||
filepath of the file to get
|
||||
path of the file to get, it should be "{ref}/{filepath}". If there is no ref could be inferred, it will be treated as the default branch
|
||||
*/
|
||||
Filepath string
|
||||
|
||||
@@ -75,7 +75,7 @@ type RepoGetRawFileParams struct {
|
||||
|
||||
/* Ref.
|
||||
|
||||
The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
The name of the commit/branch/tag. Default the repository’s default branch
|
||||
*/
|
||||
Ref *string
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ func (o *RepoGetRunnerRegistrationTokenReader) ReadResponse(response runtime.Cli
|
||||
}
|
||||
return result, nil
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/runners/registration-token] repoGetRunnerRegistrationToken", response, response.Code())
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/actions/runners/registration-token] repoGetRunnerRegistrationToken", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,11 +76,11 @@ func (o *RepoGetRunnerRegistrationTokenOK) Code() int {
|
||||
}
|
||||
|
||||
func (o *RepoGetRunnerRegistrationTokenOK) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/runners/registration-token][%d] repoGetRunnerRegistrationTokenOK", 200)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/runners/registration-token][%d] repoGetRunnerRegistrationTokenOK", 200)
|
||||
}
|
||||
|
||||
func (o *RepoGetRunnerRegistrationTokenOK) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/runners/registration-token][%d] repoGetRunnerRegistrationTokenOK", 200)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/actions/runners/registration-token][%d] repoGetRunnerRegistrationTokenOK", 200)
|
||||
}
|
||||
|
||||
func (o *RepoGetRunnerRegistrationTokenOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// NewRepoGetTagProtectionParams creates a new RepoGetTagProtectionParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoGetTagProtectionParams() *RepoGetTagProtectionParams {
|
||||
return &RepoGetTagProtectionParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetTagProtectionParamsWithTimeout creates a new RepoGetTagProtectionParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoGetTagProtectionParamsWithTimeout(timeout time.Duration) *RepoGetTagProtectionParams {
|
||||
return &RepoGetTagProtectionParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetTagProtectionParamsWithContext creates a new RepoGetTagProtectionParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoGetTagProtectionParamsWithContext(ctx context.Context) *RepoGetTagProtectionParams {
|
||||
return &RepoGetTagProtectionParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetTagProtectionParamsWithHTTPClient creates a new RepoGetTagProtectionParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoGetTagProtectionParamsWithHTTPClient(client *http.Client) *RepoGetTagProtectionParams {
|
||||
return &RepoGetTagProtectionParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetTagProtectionParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo get tag protection operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoGetTagProtectionParams struct {
|
||||
|
||||
/* ID.
|
||||
|
||||
id of the tag protect to get
|
||||
*/
|
||||
ID int64
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo get tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoGetTagProtectionParams) WithDefaults() *RepoGetTagProtectionParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo get tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoGetTagProtectionParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) WithTimeout(timeout time.Duration) *RepoGetTagProtectionParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) WithContext(ctx context.Context) *RepoGetTagProtectionParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) WithHTTPClient(client *http.Client) *RepoGetTagProtectionParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithID adds the id to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) WithID(id int64) *RepoGetTagProtectionParams {
|
||||
o.SetID(id)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetID adds the id to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) WithOwner(owner string) *RepoGetTagProtectionParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) WithRepo(repo string) *RepoGetTagProtectionParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo get tag protection params
|
||||
func (o *RepoGetTagProtectionParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoGetTagProtectionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param id
|
||||
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// RepoGetTagProtectionReader is a Reader for the RepoGetTagProtection structure.
|
||||
type RepoGetTagProtectionReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoGetTagProtectionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewRepoGetTagProtectionOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewRepoGetTagProtectionNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/tag_protections/{id}] repoGetTagProtection", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoGetTagProtectionOK creates a RepoGetTagProtectionOK with default headers values
|
||||
func NewRepoGetTagProtectionOK() *RepoGetTagProtectionOK {
|
||||
return &RepoGetTagProtectionOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetTagProtectionOK describes a response with status code 200, with default header values.
|
||||
|
||||
TagProtection
|
||||
*/
|
||||
type RepoGetTagProtectionOK struct {
|
||||
Payload *models.TagProtection
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo get tag protection o k response has a 2xx status code
|
||||
func (o *RepoGetTagProtectionOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo get tag protection o k response has a 3xx status code
|
||||
func (o *RepoGetTagProtectionOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo get tag protection o k response has a 4xx status code
|
||||
func (o *RepoGetTagProtectionOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo get tag protection o k response has a 5xx status code
|
||||
func (o *RepoGetTagProtectionOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo get tag protection o k response a status code equal to that given
|
||||
func (o *RepoGetTagProtectionOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo get tag protection o k response
|
||||
func (o *RepoGetTagProtectionOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/tag_protections/{id}][%d] repoGetTagProtectionOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/tag_protections/{id}][%d] repoGetTagProtectionOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionOK) GetPayload() *models.TagProtection {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.TagProtection)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoGetTagProtectionNotFound creates a RepoGetTagProtectionNotFound with default headers values
|
||||
func NewRepoGetTagProtectionNotFound() *RepoGetTagProtectionNotFound {
|
||||
return &RepoGetTagProtectionNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetTagProtectionNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoGetTagProtectionNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo get tag protection not found response has a 2xx status code
|
||||
func (o *RepoGetTagProtectionNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo get tag protection not found response has a 3xx status code
|
||||
func (o *RepoGetTagProtectionNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo get tag protection not found response has a 4xx status code
|
||||
func (o *RepoGetTagProtectionNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo get tag protection not found response has a 5xx status code
|
||||
func (o *RepoGetTagProtectionNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo get tag protection not found response a status code equal to that given
|
||||
func (o *RepoGetTagProtectionNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo get tag protection not found response
|
||||
func (o *RepoGetTagProtectionNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionNotFound) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/tag_protections/{id}][%d] repoGetTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionNotFound) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/tag_protections/{id}][%d] repoGetTagProtectionNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoGetTagProtectionNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -70,7 +70,7 @@ type RepoListPullRequestsParams struct {
|
||||
|
||||
/* Limit.
|
||||
|
||||
page size of results
|
||||
Page size of results
|
||||
*/
|
||||
Limit *int64
|
||||
|
||||
@@ -84,19 +84,27 @@ type RepoListPullRequestsParams struct {
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
Owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Page.
|
||||
|
||||
page number of results to return (1-based)
|
||||
Page number of results to return (1-based)
|
||||
|
||||
Default: 1
|
||||
*/
|
||||
Page *int64
|
||||
|
||||
/* Poster.
|
||||
|
||||
Filter by pull request author
|
||||
*/
|
||||
Poster *string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
Name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
@@ -108,7 +116,9 @@ type RepoListPullRequestsParams struct {
|
||||
|
||||
/* State.
|
||||
|
||||
State of pull request: open or closed (optional)
|
||||
State of pull request
|
||||
|
||||
Default: "open"
|
||||
*/
|
||||
State *string
|
||||
|
||||
@@ -129,7 +139,21 @@ func (o *RepoListPullRequestsParams) WithDefaults() *RepoListPullRequestsParams
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoListPullRequestsParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
var (
|
||||
pageDefault = int64(1)
|
||||
|
||||
stateDefault = string("open")
|
||||
)
|
||||
|
||||
val := RepoListPullRequestsParams{
|
||||
Page: &pageDefault,
|
||||
State: &stateDefault,
|
||||
}
|
||||
|
||||
val.timeout = o.timeout
|
||||
val.Context = o.Context
|
||||
val.HTTPClient = o.HTTPClient
|
||||
*o = val
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo list pull requests params
|
||||
@@ -220,6 +244,17 @@ func (o *RepoListPullRequestsParams) SetPage(page *int64) {
|
||||
o.Page = page
|
||||
}
|
||||
|
||||
// WithPoster adds the poster to the repo list pull requests params
|
||||
func (o *RepoListPullRequestsParams) WithPoster(poster *string) *RepoListPullRequestsParams {
|
||||
o.SetPoster(poster)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPoster adds the poster to the repo list pull requests params
|
||||
func (o *RepoListPullRequestsParams) SetPoster(poster *string) {
|
||||
o.Poster = poster
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo list pull requests params
|
||||
func (o *RepoListPullRequestsParams) WithRepo(repo string) *RepoListPullRequestsParams {
|
||||
o.SetRepo(repo)
|
||||
@@ -328,6 +363,23 @@ func (o *RepoListPullRequestsParams) WriteToRequest(r runtime.ClientRequest, reg
|
||||
}
|
||||
}
|
||||
|
||||
if o.Poster != nil {
|
||||
|
||||
// query param poster
|
||||
var qrPoster string
|
||||
|
||||
if o.Poster != nil {
|
||||
qrPoster = *o.Poster
|
||||
}
|
||||
qPoster := qrPoster
|
||||
if qPoster != "" {
|
||||
|
||||
if err := r.SetQueryParam("poster", qPoster); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
|
||||
@@ -36,6 +36,12 @@ func (o *RepoListPullRequestsReader) ReadResponse(response runtime.ClientRespons
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 500:
|
||||
result := NewRepoListPullRequestsInternalServerError()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/pulls] repoListPullRequests", response, response.Code())
|
||||
}
|
||||
@@ -164,3 +170,75 @@ func (o *RepoListPullRequestsNotFound) readResponse(response runtime.ClientRespo
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoListPullRequestsInternalServerError creates a RepoListPullRequestsInternalServerError with default headers values
|
||||
func NewRepoListPullRequestsInternalServerError() *RepoListPullRequestsInternalServerError {
|
||||
return &RepoListPullRequestsInternalServerError{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoListPullRequestsInternalServerError describes a response with status code 500, with default header values.
|
||||
|
||||
APIError is error format response
|
||||
*/
|
||||
type RepoListPullRequestsInternalServerError struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo list pull requests internal server error response has a 2xx status code
|
||||
func (o *RepoListPullRequestsInternalServerError) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo list pull requests internal server error response has a 3xx status code
|
||||
func (o *RepoListPullRequestsInternalServerError) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo list pull requests internal server error response has a 4xx status code
|
||||
func (o *RepoListPullRequestsInternalServerError) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo list pull requests internal server error response has a 5xx status code
|
||||
func (o *RepoListPullRequestsInternalServerError) IsServerError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo list pull requests internal server error response a status code equal to that given
|
||||
func (o *RepoListPullRequestsInternalServerError) IsCode(code int) bool {
|
||||
return code == 500
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo list pull requests internal server error response
|
||||
func (o *RepoListPullRequestsInternalServerError) Code() int {
|
||||
return 500
|
||||
}
|
||||
|
||||
func (o *RepoListPullRequestsInternalServerError) Error() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/pulls][%d] repoListPullRequestsInternalServerError", 500)
|
||||
}
|
||||
|
||||
func (o *RepoListPullRequestsInternalServerError) String() string {
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/pulls][%d] repoListPullRequestsInternalServerError", 500)
|
||||
}
|
||||
|
||||
func (o *RepoListPullRequestsInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewRepoListTagProtectionParams creates a new RepoListTagProtectionParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoListTagProtectionParams() *RepoListTagProtectionParams {
|
||||
return &RepoListTagProtectionParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoListTagProtectionParamsWithTimeout creates a new RepoListTagProtectionParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoListTagProtectionParamsWithTimeout(timeout time.Duration) *RepoListTagProtectionParams {
|
||||
return &RepoListTagProtectionParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoListTagProtectionParamsWithContext creates a new RepoListTagProtectionParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoListTagProtectionParamsWithContext(ctx context.Context) *RepoListTagProtectionParams {
|
||||
return &RepoListTagProtectionParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoListTagProtectionParamsWithHTTPClient creates a new RepoListTagProtectionParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoListTagProtectionParamsWithHTTPClient(client *http.Client) *RepoListTagProtectionParams {
|
||||
return &RepoListTagProtectionParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoListTagProtectionParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo list tag protection operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoListTagProtectionParams struct {
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo list tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoListTagProtectionParams) WithDefaults() *RepoListTagProtectionParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo list tag protection params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoListTagProtectionParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) WithTimeout(timeout time.Duration) *RepoListTagProtectionParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) WithContext(ctx context.Context) *RepoListTagProtectionParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) WithHTTPClient(client *http.Client) *RepoListTagProtectionParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) WithOwner(owner string) *RepoListTagProtectionParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) WithRepo(repo string) *RepoListTagProtectionParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo list tag protection params
|
||||
func (o *RepoListTagProtectionParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoListTagProtectionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// RepoListTagProtectionReader is a Reader for the RepoListTagProtection structure.
|
||||
type RepoListTagProtectionReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoListTagProtectionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewRepoListTagProtectionOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /repos/{owner}/{repo}/tag_protections] repoListTagProtection", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoListTagProtectionOK creates a RepoListTagProtectionOK with default headers values
|
||||
func NewRepoListTagProtectionOK() *RepoListTagProtectionOK {
|
||||
return &RepoListTagProtectionOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoListTagProtectionOK describes a response with status code 200, with default header values.
|
||||
|
||||
TagProtectionList
|
||||
*/
|
||||
type RepoListTagProtectionOK struct {
|
||||
Payload []*models.TagProtection
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo list tag protection o k response has a 2xx status code
|
||||
func (o *RepoListTagProtectionOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo list tag protection o k response has a 3xx status code
|
||||
func (o *RepoListTagProtectionOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo list tag protection o k response has a 4xx status code
|
||||
func (o *RepoListTagProtectionOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo list tag protection o k response has a 5xx status code
|
||||
func (o *RepoListTagProtectionOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo list tag protection o k response a status code equal to that given
|
||||
func (o *RepoListTagProtectionOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo list tag protection o k response
|
||||
func (o *RepoListTagProtectionOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *RepoListTagProtectionOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/tag_protections][%d] repoListTagProtectionOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoListTagProtectionOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /repos/{owner}/{repo}/tag_protections][%d] repoListTagProtectionOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoListTagProtectionOK) GetPayload() []*models.TagProtection {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *RepoListTagProtectionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// NewRepoMergeUpstreamParams creates a new RepoMergeUpstreamParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoMergeUpstreamParams() *RepoMergeUpstreamParams {
|
||||
return &RepoMergeUpstreamParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoMergeUpstreamParamsWithTimeout creates a new RepoMergeUpstreamParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoMergeUpstreamParamsWithTimeout(timeout time.Duration) *RepoMergeUpstreamParams {
|
||||
return &RepoMergeUpstreamParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoMergeUpstreamParamsWithContext creates a new RepoMergeUpstreamParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoMergeUpstreamParamsWithContext(ctx context.Context) *RepoMergeUpstreamParams {
|
||||
return &RepoMergeUpstreamParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoMergeUpstreamParamsWithHTTPClient creates a new RepoMergeUpstreamParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoMergeUpstreamParamsWithHTTPClient(client *http.Client) *RepoMergeUpstreamParams {
|
||||
return &RepoMergeUpstreamParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoMergeUpstreamParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo merge upstream operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoMergeUpstreamParams struct {
|
||||
|
||||
// Body.
|
||||
Body *models.MergeUpstreamRequest
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo merge upstream params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoMergeUpstreamParams) WithDefaults() *RepoMergeUpstreamParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo merge upstream params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoMergeUpstreamParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) WithTimeout(timeout time.Duration) *RepoMergeUpstreamParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) WithContext(ctx context.Context) *RepoMergeUpstreamParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) WithHTTPClient(client *http.Client) *RepoMergeUpstreamParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) WithBody(body *models.MergeUpstreamRequest) *RepoMergeUpstreamParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) SetBody(body *models.MergeUpstreamRequest) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) WithOwner(owner string) *RepoMergeUpstreamParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) WithRepo(repo string) *RepoMergeUpstreamParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo merge upstream params
|
||||
func (o *RepoMergeUpstreamParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoMergeUpstreamParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// RepoMergeUpstreamReader is a Reader for the RepoMergeUpstream structure.
|
||||
type RepoMergeUpstreamReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoMergeUpstreamReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewRepoMergeUpstreamOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 400:
|
||||
result := NewRepoMergeUpstreamBadRequest()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 404:
|
||||
result := NewRepoMergeUpstreamNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[POST /repos/{owner}/{repo}/merge-upstream] repoMergeUpstream", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoMergeUpstreamOK creates a RepoMergeUpstreamOK with default headers values
|
||||
func NewRepoMergeUpstreamOK() *RepoMergeUpstreamOK {
|
||||
return &RepoMergeUpstreamOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoMergeUpstreamOK describes a response with status code 200, with default header values.
|
||||
|
||||
RepoMergeUpstreamOK repo merge upstream o k
|
||||
*/
|
||||
type RepoMergeUpstreamOK struct {
|
||||
Payload *models.MergeUpstreamResponse
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo merge upstream o k response has a 2xx status code
|
||||
func (o *RepoMergeUpstreamOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo merge upstream o k response has a 3xx status code
|
||||
func (o *RepoMergeUpstreamOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo merge upstream o k response has a 4xx status code
|
||||
func (o *RepoMergeUpstreamOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo merge upstream o k response has a 5xx status code
|
||||
func (o *RepoMergeUpstreamOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo merge upstream o k response a status code equal to that given
|
||||
func (o *RepoMergeUpstreamOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo merge upstream o k response
|
||||
func (o *RepoMergeUpstreamOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/merge-upstream][%d] repoMergeUpstreamOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/merge-upstream][%d] repoMergeUpstreamOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamOK) GetPayload() *models.MergeUpstreamResponse {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.MergeUpstreamResponse)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoMergeUpstreamBadRequest creates a RepoMergeUpstreamBadRequest with default headers values
|
||||
func NewRepoMergeUpstreamBadRequest() *RepoMergeUpstreamBadRequest {
|
||||
return &RepoMergeUpstreamBadRequest{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoMergeUpstreamBadRequest describes a response with status code 400, with default header values.
|
||||
|
||||
APIError is error format response
|
||||
*/
|
||||
type RepoMergeUpstreamBadRequest struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo merge upstream bad request response has a 2xx status code
|
||||
func (o *RepoMergeUpstreamBadRequest) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo merge upstream bad request response has a 3xx status code
|
||||
func (o *RepoMergeUpstreamBadRequest) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo merge upstream bad request response has a 4xx status code
|
||||
func (o *RepoMergeUpstreamBadRequest) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo merge upstream bad request response has a 5xx status code
|
||||
func (o *RepoMergeUpstreamBadRequest) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo merge upstream bad request response a status code equal to that given
|
||||
func (o *RepoMergeUpstreamBadRequest) IsCode(code int) bool {
|
||||
return code == 400
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo merge upstream bad request response
|
||||
func (o *RepoMergeUpstreamBadRequest) Code() int {
|
||||
return 400
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamBadRequest) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/merge-upstream][%d] repoMergeUpstreamBadRequest", 400)
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamBadRequest) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/merge-upstream][%d] repoMergeUpstreamBadRequest", 400)
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoMergeUpstreamNotFound creates a RepoMergeUpstreamNotFound with default headers values
|
||||
func NewRepoMergeUpstreamNotFound() *RepoMergeUpstreamNotFound {
|
||||
return &RepoMergeUpstreamNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoMergeUpstreamNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoMergeUpstreamNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo merge upstream not found response has a 2xx status code
|
||||
func (o *RepoMergeUpstreamNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo merge upstream not found response has a 3xx status code
|
||||
func (o *RepoMergeUpstreamNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo merge upstream not found response has a 4xx status code
|
||||
func (o *RepoMergeUpstreamNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo merge upstream not found response has a 5xx status code
|
||||
func (o *RepoMergeUpstreamNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo merge upstream not found response a status code equal to that given
|
||||
func (o *RepoMergeUpstreamNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo merge upstream not found response
|
||||
func (o *RepoMergeUpstreamNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamNotFound) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/merge-upstream][%d] repoMergeUpstreamNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamNotFound) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/merge-upstream][%d] repoMergeUpstreamNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoMergeUpstreamNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -132,7 +132,7 @@ type RepoSearchParams struct {
|
||||
|
||||
/* Sort.
|
||||
|
||||
sort repos by attribute. Supported values are "alpha", "created", "updated", "size", and "id". Default is "alpha"
|
||||
sort repos by attribute. Supported values are "alpha", "created", "updated", "size", "git_size", "lfs_size", "stars", "forks" and "id". Default is "alpha"
|
||||
*/
|
||||
Sort *string
|
||||
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// NewRepoUpdateBranchParams creates a new RepoUpdateBranchParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoUpdateBranchParams() *RepoUpdateBranchParams {
|
||||
return &RepoUpdateBranchParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchParamsWithTimeout creates a new RepoUpdateBranchParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoUpdateBranchParamsWithTimeout(timeout time.Duration) *RepoUpdateBranchParams {
|
||||
return &RepoUpdateBranchParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchParamsWithContext creates a new RepoUpdateBranchParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoUpdateBranchParamsWithContext(ctx context.Context) *RepoUpdateBranchParams {
|
||||
return &RepoUpdateBranchParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchParamsWithHTTPClient creates a new RepoUpdateBranchParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoUpdateBranchParamsWithHTTPClient(client *http.Client) *RepoUpdateBranchParams {
|
||||
return &RepoUpdateBranchParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo update branch operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoUpdateBranchParams struct {
|
||||
|
||||
// Body.
|
||||
Body *models.UpdateBranchRepoOption
|
||||
|
||||
/* Branch.
|
||||
|
||||
name of the branch
|
||||
*/
|
||||
Branch string
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo update branch params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoUpdateBranchParams) WithDefaults() *RepoUpdateBranchParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo update branch params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoUpdateBranchParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithTimeout(timeout time.Duration) *RepoUpdateBranchParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithContext(ctx context.Context) *RepoUpdateBranchParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithHTTPClient(client *http.Client) *RepoUpdateBranchParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithBody(body *models.UpdateBranchRepoOption) *RepoUpdateBranchParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetBody(body *models.UpdateBranchRepoOption) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithBranch adds the branch to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithBranch(branch string) *RepoUpdateBranchParams {
|
||||
o.SetBranch(branch)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBranch adds the branch to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetBranch(branch string) {
|
||||
o.Branch = branch
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithOwner(owner string) *RepoUpdateBranchParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) WithRepo(repo string) *RepoUpdateBranchParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo update branch params
|
||||
func (o *RepoUpdateBranchParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoUpdateBranchParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// path param branch
|
||||
if err := r.SetPathParam("branch", o.Branch); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesParams creates a new RepoUpdateBranchProtectionPrioriesParams object,
|
||||
// with the default timeout for this client.
|
||||
//
|
||||
// Default values are not hydrated, since defaults are normally applied by the API server side.
|
||||
//
|
||||
// To enforce default values in parameter, use SetDefaults or WithDefaults.
|
||||
func NewRepoUpdateBranchProtectionPrioriesParams() *RepoUpdateBranchProtectionPrioriesParams {
|
||||
return &RepoUpdateBranchProtectionPrioriesParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesParamsWithTimeout creates a new RepoUpdateBranchProtectionPrioriesParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewRepoUpdateBranchProtectionPrioriesParamsWithTimeout(timeout time.Duration) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
return &RepoUpdateBranchProtectionPrioriesParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesParamsWithContext creates a new RepoUpdateBranchProtectionPrioriesParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewRepoUpdateBranchProtectionPrioriesParamsWithContext(ctx context.Context) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
return &RepoUpdateBranchProtectionPrioriesParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesParamsWithHTTPClient creates a new RepoUpdateBranchProtectionPrioriesParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewRepoUpdateBranchProtectionPrioriesParamsWithHTTPClient(client *http.Client) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
return &RepoUpdateBranchProtectionPrioriesParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchProtectionPrioriesParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the repo update branch protection priories operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type RepoUpdateBranchProtectionPrioriesParams struct {
|
||||
|
||||
// Body.
|
||||
Body *models.UpdateBranchProtectionPriories
|
||||
|
||||
/* Owner.
|
||||
|
||||
owner of the repo
|
||||
*/
|
||||
Owner string
|
||||
|
||||
/* Repo.
|
||||
|
||||
name of the repo
|
||||
*/
|
||||
Repo string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the repo update branch protection priories params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithDefaults() *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the repo update branch protection priories params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithTimeout(timeout time.Duration) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithContext(ctx context.Context) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithHTTPClient(client *http.Client) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithBody(body *models.UpdateBranchProtectionPriories) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetBody(body *models.UpdateBranchProtectionPriories) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithOwner adds the owner to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithOwner(owner string) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetOwner(owner)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetOwner adds the owner to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetOwner(owner string) {
|
||||
o.Owner = owner
|
||||
}
|
||||
|
||||
// WithRepo adds the repo to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WithRepo(repo string) *RepoUpdateBranchProtectionPrioriesParams {
|
||||
o.SetRepo(repo)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetRepo adds the repo to the repo update branch protection priories params
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) SetRepo(repo string) {
|
||||
o.Repo = repo
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *RepoUpdateBranchProtectionPrioriesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// path param owner
|
||||
if err := r.SetPathParam("owner", o.Owner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// path param repo
|
||||
if err := r.SetPathParam("repo", o.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// RepoUpdateBranchProtectionPrioriesReader is a Reader for the RepoUpdateBranchProtectionPriories structure.
|
||||
type RepoUpdateBranchProtectionPrioriesReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoUpdateBranchProtectionPrioriesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 204:
|
||||
result := NewRepoUpdateBranchProtectionPrioriesNoContent()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewRepoUpdateBranchProtectionPrioriesNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewRepoUpdateBranchProtectionPrioriesUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 423:
|
||||
result := NewRepoUpdateBranchProtectionPrioriesLocked()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[POST /repos/{owner}/{repo}/branch_protections/priority] repoUpdateBranchProtectionPriories", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesNoContent creates a RepoUpdateBranchProtectionPrioriesNoContent with default headers values
|
||||
func NewRepoUpdateBranchProtectionPrioriesNoContent() *RepoUpdateBranchProtectionPrioriesNoContent {
|
||||
return &RepoUpdateBranchProtectionPrioriesNoContent{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchProtectionPrioriesNoContent describes a response with status code 204, with default header values.
|
||||
|
||||
APIEmpty is an empty response
|
||||
*/
|
||||
type RepoUpdateBranchProtectionPrioriesNoContent struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch protection priories no content response has a 2xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch protection priories no content response has a 3xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch protection priories no content response has a 4xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch protection priories no content response has a 5xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch protection priories no content response a status code equal to that given
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) IsCode(code int) bool {
|
||||
return code == 204
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch protection priories no content response
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) Code() int {
|
||||
return 204
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesNotFound creates a RepoUpdateBranchProtectionPrioriesNotFound with default headers values
|
||||
func NewRepoUpdateBranchProtectionPrioriesNotFound() *RepoUpdateBranchProtectionPrioriesNotFound {
|
||||
return &RepoUpdateBranchProtectionPrioriesNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchProtectionPrioriesNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoUpdateBranchProtectionPrioriesNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch protection priories not found response has a 2xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch protection priories not found response has a 3xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch protection priories not found response has a 4xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch protection priories not found response has a 5xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch protection priories not found response a status code equal to that given
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch protection priories not found response
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesUnprocessableEntity creates a RepoUpdateBranchProtectionPrioriesUnprocessableEntity with default headers values
|
||||
func NewRepoUpdateBranchProtectionPrioriesUnprocessableEntity() *RepoUpdateBranchProtectionPrioriesUnprocessableEntity {
|
||||
return &RepoUpdateBranchProtectionPrioriesUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchProtectionPrioriesUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type RepoUpdateBranchProtectionPrioriesUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch protection priories unprocessable entity response has a 2xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch protection priories unprocessable entity response has a 3xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch protection priories unprocessable entity response has a 4xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch protection priories unprocessable entity response has a 5xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch protection priories unprocessable entity response a status code equal to that given
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch protection priories unprocessable entity response
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchProtectionPrioriesLocked creates a RepoUpdateBranchProtectionPrioriesLocked with default headers values
|
||||
func NewRepoUpdateBranchProtectionPrioriesLocked() *RepoUpdateBranchProtectionPrioriesLocked {
|
||||
return &RepoUpdateBranchProtectionPrioriesLocked{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchProtectionPrioriesLocked describes a response with status code 423, with default header values.
|
||||
|
||||
APIRepoArchivedError is an error that is raised when an archived repo should be modified
|
||||
*/
|
||||
type RepoUpdateBranchProtectionPrioriesLocked struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch protection priories locked response has a 2xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch protection priories locked response has a 3xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch protection priories locked response has a 4xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch protection priories locked response has a 5xx status code
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch protection priories locked response a status code equal to that given
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) IsCode(code int) bool {
|
||||
return code == 423
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch protection priories locked response
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) Code() int {
|
||||
return 423
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) Error() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesLocked", 423)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) String() string {
|
||||
return fmt.Sprintf("[POST /repos/{owner}/{repo}/branch_protections/priority][%d] repoUpdateBranchProtectionPrioriesLocked", 423)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchProtectionPrioriesLocked) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// RepoUpdateBranchReader is a Reader for the RepoUpdateBranch structure.
|
||||
type RepoUpdateBranchReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *RepoUpdateBranchReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 204:
|
||||
result := NewRepoUpdateBranchNoContent()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 403:
|
||||
result := NewRepoUpdateBranchForbidden()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 404:
|
||||
result := NewRepoUpdateBranchNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewRepoUpdateBranchUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[PATCH /repos/{owner}/{repo}/branches/{branch}] repoUpdateBranch", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchNoContent creates a RepoUpdateBranchNoContent with default headers values
|
||||
func NewRepoUpdateBranchNoContent() *RepoUpdateBranchNoContent {
|
||||
return &RepoUpdateBranchNoContent{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchNoContent describes a response with status code 204, with default header values.
|
||||
|
||||
APIEmpty is an empty response
|
||||
*/
|
||||
type RepoUpdateBranchNoContent struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch no content response has a 2xx status code
|
||||
func (o *RepoUpdateBranchNoContent) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch no content response has a 3xx status code
|
||||
func (o *RepoUpdateBranchNoContent) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch no content response has a 4xx status code
|
||||
func (o *RepoUpdateBranchNoContent) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch no content response has a 5xx status code
|
||||
func (o *RepoUpdateBranchNoContent) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch no content response a status code equal to that given
|
||||
func (o *RepoUpdateBranchNoContent) IsCode(code int) bool {
|
||||
return code == 204
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch no content response
|
||||
func (o *RepoUpdateBranchNoContent) Code() int {
|
||||
return 204
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchNoContent) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchNoContent) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchForbidden creates a RepoUpdateBranchForbidden with default headers values
|
||||
func NewRepoUpdateBranchForbidden() *RepoUpdateBranchForbidden {
|
||||
return &RepoUpdateBranchForbidden{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchForbidden describes a response with status code 403, with default header values.
|
||||
|
||||
APIForbiddenError is a forbidden error response
|
||||
*/
|
||||
type RepoUpdateBranchForbidden struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch forbidden response has a 2xx status code
|
||||
func (o *RepoUpdateBranchForbidden) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch forbidden response has a 3xx status code
|
||||
func (o *RepoUpdateBranchForbidden) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch forbidden response has a 4xx status code
|
||||
func (o *RepoUpdateBranchForbidden) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch forbidden response has a 5xx status code
|
||||
func (o *RepoUpdateBranchForbidden) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch forbidden response a status code equal to that given
|
||||
func (o *RepoUpdateBranchForbidden) IsCode(code int) bool {
|
||||
return code == 403
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch forbidden response
|
||||
func (o *RepoUpdateBranchForbidden) Code() int {
|
||||
return 403
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchForbidden) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchForbidden", 403)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchForbidden) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchForbidden", 403)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchNotFound creates a RepoUpdateBranchNotFound with default headers values
|
||||
func NewRepoUpdateBranchNotFound() *RepoUpdateBranchNotFound {
|
||||
return &RepoUpdateBranchNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
APINotFound is a not found empty response
|
||||
*/
|
||||
type RepoUpdateBranchNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch not found response has a 2xx status code
|
||||
func (o *RepoUpdateBranchNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch not found response has a 3xx status code
|
||||
func (o *RepoUpdateBranchNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch not found response has a 4xx status code
|
||||
func (o *RepoUpdateBranchNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch not found response has a 5xx status code
|
||||
func (o *RepoUpdateBranchNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch not found response a status code equal to that given
|
||||
func (o *RepoUpdateBranchNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch not found response
|
||||
func (o *RepoUpdateBranchNotFound) Code() int {
|
||||
return 404
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchNotFound) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchNotFound) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchNotFound", 404)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoUpdateBranchUnprocessableEntity creates a RepoUpdateBranchUnprocessableEntity with default headers values
|
||||
func NewRepoUpdateBranchUnprocessableEntity() *RepoUpdateBranchUnprocessableEntity {
|
||||
return &RepoUpdateBranchUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchUnprocessableEntity describes a response with status code 422, with default header values.
|
||||
|
||||
APIValidationError is error format response related to input validation
|
||||
*/
|
||||
type RepoUpdateBranchUnprocessableEntity struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this repo update branch unprocessable entity response has a 2xx status code
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this repo update branch unprocessable entity response has a 3xx status code
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this repo update branch unprocessable entity response has a 4xx status code
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this repo update branch unprocessable entity response has a 5xx status code
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this repo update branch unprocessable entity response a status code equal to that given
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) IsCode(code int) bool {
|
||||
return code == 422
|
||||
}
|
||||
|
||||
// Code gets the status code for the repo update branch unprocessable entity response
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) Code() int {
|
||||
return 422
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) String() string {
|
||||
return fmt.Sprintf("[PATCH /repos/{owner}/{repo}/branches/{branch}][%d] repoUpdateBranchUnprocessableEntity", 422)
|
||||
}
|
||||
|
||||
func (o *RepoUpdateBranchUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// hydrates response header message
|
||||
hdrMessage := response.GetHeader("message")
|
||||
|
||||
if hdrMessage != "" {
|
||||
o.Message = hdrMessage
|
||||
}
|
||||
|
||||
// hydrates response header url
|
||||
hdrURL := response.GetHeader("url")
|
||||
|
||||
if hdrURL != "" {
|
||||
o.URL = hdrURL
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -127,6 +127,8 @@ type ClientService interface {
|
||||
|
||||
GetTree(params *GetTreeParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTreeOK, error)
|
||||
|
||||
ListActionTasks(params *ListActionTasksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListActionTasksOK, error)
|
||||
|
||||
AcceptRepoTransfer(params *AcceptRepoTransferParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AcceptRepoTransferAccepted, error)
|
||||
|
||||
CreateCurrentUserRepo(params *CreateCurrentUserRepoParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateCurrentUserRepoCreated, error)
|
||||
@@ -193,6 +195,8 @@ type ClientService interface {
|
||||
|
||||
RepoCreateTag(params *RepoCreateTagParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoCreateTagOK, error)
|
||||
|
||||
RepoCreateTagProtection(params *RepoCreateTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoCreateTagProtectionCreated, error)
|
||||
|
||||
RepoCreateWikiPage(params *RepoCreateWikiPageParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoCreateWikiPageCreated, error)
|
||||
|
||||
RepoDelete(params *RepoDeleteParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoDeleteNoContent, error)
|
||||
@@ -227,6 +231,8 @@ type ClientService interface {
|
||||
|
||||
RepoDeleteTag(params *RepoDeleteTagParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoDeleteTagNoContent, error)
|
||||
|
||||
RepoDeleteTagProtection(params *RepoDeleteTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoDeleteTagProtectionNoContent, error)
|
||||
|
||||
RepoDeleteTeam(params *RepoDeleteTeamParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoDeleteTeamNoContent, error)
|
||||
|
||||
RepoDeleteTopic(params *RepoDeleteTopicParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoDeleteTopicNoContent, error)
|
||||
@@ -253,6 +259,8 @@ type ClientService interface {
|
||||
|
||||
RepoEditReleaseAttachment(params *RepoEditReleaseAttachmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoEditReleaseAttachmentCreated, error)
|
||||
|
||||
RepoEditTagProtection(params *RepoEditTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoEditTagProtectionOK, error)
|
||||
|
||||
RepoEditWikiPage(params *RepoEditWikiPageParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoEditWikiPageOK, error)
|
||||
|
||||
RepoGet(params *RepoGetParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetOK, error)
|
||||
@@ -293,6 +301,8 @@ type ClientService interface {
|
||||
|
||||
RepoGetLatestRelease(params *RepoGetLatestReleaseParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetLatestReleaseOK, error)
|
||||
|
||||
RepoGetLicenses(params *RepoGetLicensesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetLicensesOK, error)
|
||||
|
||||
RepoGetNote(params *RepoGetNoteParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetNoteOK, error)
|
||||
|
||||
RepoGetPullRequest(params *RepoGetPullRequestParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetPullRequestOK, error)
|
||||
@@ -329,6 +339,8 @@ type ClientService interface {
|
||||
|
||||
RepoGetTag(params *RepoGetTagParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetTagOK, error)
|
||||
|
||||
RepoGetTagProtection(params *RepoGetTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetTagProtectionOK, error)
|
||||
|
||||
RepoGetWikiPage(params *RepoGetWikiPageParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetWikiPageOK, error)
|
||||
|
||||
RepoGetWikiPageRevisions(params *RepoGetWikiPageRevisionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetWikiPageRevisionsOK, error)
|
||||
@@ -377,6 +389,8 @@ type ClientService interface {
|
||||
|
||||
RepoListSubscribers(params *RepoListSubscribersParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoListSubscribersOK, error)
|
||||
|
||||
RepoListTagProtection(params *RepoListTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoListTagProtectionOK, error)
|
||||
|
||||
RepoListTags(params *RepoListTagsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoListTagsOK, error)
|
||||
|
||||
RepoListTeams(params *RepoListTeamsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoListTeamsOK, error)
|
||||
@@ -385,6 +399,8 @@ type ClientService interface {
|
||||
|
||||
RepoMergePullRequest(params *RepoMergePullRequestParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoMergePullRequestOK, error)
|
||||
|
||||
RepoMergeUpstream(params *RepoMergeUpstreamParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoMergeUpstreamOK, error)
|
||||
|
||||
RepoMigrate(params *RepoMigrateParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoMigrateCreated, error)
|
||||
|
||||
RepoMirrorSync(params *RepoMirrorSyncParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoMirrorSyncOK, error)
|
||||
@@ -411,6 +427,10 @@ type ClientService interface {
|
||||
|
||||
RepoUpdateAvatar(params *RepoUpdateAvatarParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdateAvatarNoContent, error)
|
||||
|
||||
RepoUpdateBranch(params *RepoUpdateBranchParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdateBranchNoContent, error)
|
||||
|
||||
RepoUpdateBranchProtectionPriories(params *RepoUpdateBranchProtectionPrioriesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdateBranchProtectionPrioriesNoContent, error)
|
||||
|
||||
RepoUpdateFile(params *RepoUpdateFileParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdateFileOK, error)
|
||||
|
||||
RepoUpdatePullRequest(params *RepoUpdatePullRequestParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdatePullRequestOK, error)
|
||||
@@ -553,6 +573,45 @@ func (a *Client) GetTree(params *GetTreeParams, authInfo runtime.ClientAuthInfoW
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
ListActionTasks lists a repository s action tasks
|
||||
*/
|
||||
func (a *Client) ListActionTasks(params *ListActionTasksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListActionTasksOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewListActionTasksParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "ListActionTasks",
|
||||
Method: "GET",
|
||||
PathPattern: "/repos/{owner}/{repo}/actions/tasks",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &ListActionTasksReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*ListActionTasksOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for ListActionTasks: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
AcceptRepoTransfer accepts a repo transfer
|
||||
*/
|
||||
@@ -987,7 +1046,7 @@ func (a *Client) RejectRepoTransfer(params *RejectRepoTransferParams, authInfo r
|
||||
}
|
||||
|
||||
/*
|
||||
RepoAddCollaborator adds a collaborator to a repository
|
||||
RepoAddCollaborator adds or update a collaborator to a repository
|
||||
*/
|
||||
func (a *Client) RepoAddCollaborator(params *RepoAddCollaboratorParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoAddCollaboratorNoContent, error) {
|
||||
// TODO: Validate the params before sending
|
||||
@@ -1844,6 +1903,45 @@ func (a *Client) RepoCreateTag(params *RepoCreateTagParams, authInfo runtime.Cli
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateTagProtection creates a tag protections for a repository
|
||||
*/
|
||||
func (a *Client) RepoCreateTagProtection(params *RepoCreateTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoCreateTagProtectionCreated, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoCreateTagProtectionParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoCreateTagProtection",
|
||||
Method: "POST",
|
||||
PathPattern: "/repos/{owner}/{repo}/tag_protections",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoCreateTagProtectionReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoCreateTagProtectionCreated)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoCreateTagProtection: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoCreateWikiPage creates a wiki page
|
||||
*/
|
||||
@@ -2507,6 +2605,45 @@ func (a *Client) RepoDeleteTag(params *RepoDeleteTagParams, authInfo runtime.Cli
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoDeleteTagProtection deletes a specific tag protection for the repository
|
||||
*/
|
||||
func (a *Client) RepoDeleteTagProtection(params *RepoDeleteTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoDeleteTagProtectionNoContent, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoDeleteTagProtectionParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoDeleteTagProtection",
|
||||
Method: "DELETE",
|
||||
PathPattern: "/repos/{owner}/{repo}/tag_protections/{id}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoDeleteTagProtectionReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoDeleteTagProtectionNoContent)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoDeleteTagProtection: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoDeleteTeam deletes a team from a repository
|
||||
*/
|
||||
@@ -3014,6 +3151,45 @@ func (a *Client) RepoEditReleaseAttachment(params *RepoEditReleaseAttachmentPara
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditTagProtection edits a tag protections for a repository only fields that are set will be changed
|
||||
*/
|
||||
func (a *Client) RepoEditTagProtection(params *RepoEditTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoEditTagProtectionOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoEditTagProtectionParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoEditTagProtection",
|
||||
Method: "PATCH",
|
||||
PathPattern: "/repos/{owner}/{repo}/tag_protections/{id}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoEditTagProtectionReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoEditTagProtectionOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoEditTagProtection: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoEditWikiPage edits a wiki page
|
||||
*/
|
||||
@@ -3366,7 +3542,7 @@ func (a *Client) RepoGetCombinedStatusByRef(params *RepoGetCombinedStatusByRefPa
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetCommitPullRequest gets the pull request of the commit
|
||||
RepoGetCommitPullRequest gets the merged pull request of the commit
|
||||
*/
|
||||
func (a *Client) RepoGetCommitPullRequest(params *RepoGetCommitPullRequestParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetCommitPullRequestOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
@@ -3794,6 +3970,45 @@ func (a *Client) RepoGetLatestRelease(params *RepoGetLatestReleaseParams, authIn
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetLicenses gets repo licenses
|
||||
*/
|
||||
func (a *Client) RepoGetLicenses(params *RepoGetLicensesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetLicensesOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoGetLicensesParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoGetLicenses",
|
||||
Method: "GET",
|
||||
PathPattern: "/repos/{owner}/{repo}/licenses",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoGetLicensesReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoGetLicensesOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoGetLicenses: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetNote gets a note corresponding to a single commit from a repository
|
||||
*/
|
||||
@@ -4119,7 +4334,7 @@ func (a *Client) RepoGetRawFile(params *RepoGetRawFileParams, authInfo runtime.C
|
||||
Method: "GET",
|
||||
PathPattern: "/repos/{owner}/{repo}/raw/{filepath}",
|
||||
ProducesMediaTypes: []string{"application/octet-stream"},
|
||||
ConsumesMediaTypes: []string{"application/octet-stream"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoGetRawFileReader{formats: a.formats, writer: writer},
|
||||
@@ -4390,7 +4605,7 @@ func (a *Client) RepoGetRunnerRegistrationToken(params *RepoGetRunnerRegistratio
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoGetRunnerRegistrationToken",
|
||||
Method: "GET",
|
||||
PathPattern: "/repos/{owner}/{repo}/runners/registration-token",
|
||||
PathPattern: "/repos/{owner}/{repo}/actions/runners/registration-token",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
@@ -4496,6 +4711,45 @@ func (a *Client) RepoGetTag(params *RepoGetTagParams, authInfo runtime.ClientAut
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetTagProtection gets a specific tag protection for the repository
|
||||
*/
|
||||
func (a *Client) RepoGetTagProtection(params *RepoGetTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoGetTagProtectionOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoGetTagProtectionParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoGetTagProtection",
|
||||
Method: "GET",
|
||||
PathPattern: "/repos/{owner}/{repo}/tag_protections/{id}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoGetTagProtectionReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoGetTagProtectionOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoGetTagProtection: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoGetWikiPage gets a wiki page
|
||||
*/
|
||||
@@ -5432,6 +5686,45 @@ func (a *Client) RepoListSubscribers(params *RepoListSubscribersParams, authInfo
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoListTagProtection lists tag protections for a repository
|
||||
*/
|
||||
func (a *Client) RepoListTagProtection(params *RepoListTagProtectionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoListTagProtectionOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoListTagProtectionParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoListTagProtection",
|
||||
Method: "GET",
|
||||
PathPattern: "/repos/{owner}/{repo}/tag_protections",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoListTagProtectionReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoListTagProtectionOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoListTagProtection: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoListTags lists a repository s tags
|
||||
*/
|
||||
@@ -5588,6 +5881,45 @@ func (a *Client) RepoMergePullRequest(params *RepoMergePullRequestParams, authIn
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoMergeUpstream merges a branch from upstream
|
||||
*/
|
||||
func (a *Client) RepoMergeUpstream(params *RepoMergeUpstreamParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoMergeUpstreamOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoMergeUpstreamParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoMergeUpstream",
|
||||
Method: "POST",
|
||||
PathPattern: "/repos/{owner}/{repo}/merge-upstream",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoMergeUpstreamReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoMergeUpstreamOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoMergeUpstream: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoMigrate migrates a remote git repository
|
||||
*/
|
||||
@@ -6095,6 +6427,84 @@ func (a *Client) RepoUpdateAvatar(params *RepoUpdateAvatarParams, authInfo runti
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranch updates a branch
|
||||
*/
|
||||
func (a *Client) RepoUpdateBranch(params *RepoUpdateBranchParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdateBranchNoContent, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoUpdateBranchParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoUpdateBranch",
|
||||
Method: "PATCH",
|
||||
PathPattern: "/repos/{owner}/{repo}/branches/{branch}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoUpdateBranchReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoUpdateBranchNoContent)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoUpdateBranch: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateBranchProtectionPriories updates the priorities of branch protections for a repository
|
||||
*/
|
||||
func (a *Client) RepoUpdateBranchProtectionPriories(params *RepoUpdateBranchProtectionPrioriesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RepoUpdateBranchProtectionPrioriesNoContent, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewRepoUpdateBranchProtectionPrioriesParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "repoUpdateBranchProtectionPriories",
|
||||
Method: "POST",
|
||||
PathPattern: "/repos/{owner}/{repo}/branch_protections/priority",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &RepoUpdateBranchProtectionPrioriesReader{formats: a.formats},
|
||||
AuthInfo: authInfo,
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(op)
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(op)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*RepoUpdateBranchProtectionPrioriesNoContent)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for repoUpdateBranchProtectionPriories: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
RepoUpdateFile updates a file in a repository
|
||||
*/
|
||||
|
||||
144
common/gitea-generated/models/action_task.go
Normal file
144
common/gitea-generated/models/action_task.go
Normal file
@@ -0,0 +1,144 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// ActionTask ActionTask represents a ActionTask
|
||||
//
|
||||
// swagger:model ActionTask
|
||||
type ActionTask struct {
|
||||
|
||||
// created at
|
||||
// Format: date-time
|
||||
CreatedAt strfmt.DateTime `json:"created_at,omitempty"`
|
||||
|
||||
// display title
|
||||
DisplayTitle string `json:"display_title,omitempty"`
|
||||
|
||||
// event
|
||||
Event string `json:"event,omitempty"`
|
||||
|
||||
// head branch
|
||||
HeadBranch string `json:"head_branch,omitempty"`
|
||||
|
||||
// head s h a
|
||||
HeadSHA string `json:"head_sha,omitempty"`
|
||||
|
||||
// ID
|
||||
ID int64 `json:"id,omitempty"`
|
||||
|
||||
// name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// run number
|
||||
RunNumber int64 `json:"run_number,omitempty"`
|
||||
|
||||
// run started at
|
||||
// Format: date-time
|
||||
RunStartedAt strfmt.DateTime `json:"run_started_at,omitempty"`
|
||||
|
||||
// status
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// URL
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// updated at
|
||||
// Format: date-time
|
||||
UpdatedAt strfmt.DateTime `json:"updated_at,omitempty"`
|
||||
|
||||
// workflow ID
|
||||
WorkflowID string `json:"workflow_id,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this action task
|
||||
func (m *ActionTask) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateCreatedAt(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateRunStartedAt(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateUpdatedAt(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ActionTask) validateCreatedAt(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.CreatedAt) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validate.FormatOf("created_at", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ActionTask) validateRunStartedAt(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.RunStartedAt) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validate.FormatOf("run_started_at", "body", "date-time", m.RunStartedAt.String(), formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ActionTask) validateUpdatedAt(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.UpdatedAt) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validate.FormatOf("updated_at", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this action task based on context it is used
|
||||
func (m *ActionTask) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *ActionTask) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *ActionTask) UnmarshalBinary(b []byte) error {
|
||||
var res ActionTask
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
124
common/gitea-generated/models/action_task_response.go
Normal file
124
common/gitea-generated/models/action_task_response.go
Normal file
@@ -0,0 +1,124 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// ActionTaskResponse ActionTaskResponse returns a ActionTask
|
||||
//
|
||||
// swagger:model ActionTaskResponse
|
||||
type ActionTaskResponse struct {
|
||||
|
||||
// entries
|
||||
Entries []*ActionTask `json:"workflow_runs"`
|
||||
|
||||
// total count
|
||||
TotalCount int64 `json:"total_count,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this action task response
|
||||
func (m *ActionTaskResponse) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateEntries(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ActionTaskResponse) validateEntries(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Entries) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < len(m.Entries); i++ {
|
||||
if swag.IsZero(m.Entries[i]) { // not required
|
||||
continue
|
||||
}
|
||||
|
||||
if m.Entries[i] != nil {
|
||||
if err := m.Entries[i].Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("workflow_runs" + "." + strconv.Itoa(i))
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("workflow_runs" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validate this action task response based on the context it is used
|
||||
func (m *ActionTaskResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.contextValidateEntries(ctx, formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ActionTaskResponse) contextValidateEntries(ctx context.Context, formats strfmt.Registry) error {
|
||||
|
||||
for i := 0; i < len(m.Entries); i++ {
|
||||
|
||||
if m.Entries[i] != nil {
|
||||
|
||||
if swag.IsZero(m.Entries[i]) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := m.Entries[i].ContextValidate(ctx, formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("workflow_runs" + "." + strconv.Itoa(i))
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("workflow_runs" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *ActionTaskResponse) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *ActionTaskResponse) UnmarshalBinary(b []byte) error {
|
||||
var res ActionTaskResponse
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -7,6 +7,7 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
@@ -38,7 +39,8 @@ type Activity struct {
|
||||
// is private
|
||||
IsPrivate bool `json:"is_private,omitempty"`
|
||||
|
||||
// op type
|
||||
// the type of action
|
||||
// Enum: ["create_repo","rename_repo","star_repo","watch_repo","commit_repo","create_issue","create_pull_request","transfer_repo","push_tag","comment_issue","merge_pull_request","close_issue","reopen_issue","close_pull_request","reopen_pull_request","delete_tag","delete_branch","mirror_sync_push","mirror_sync_create","mirror_sync_delete","approve_pull_request","reject_pull_request","comment_pull","publish_release","pull_review_dismissed","pull_request_ready_for_review","auto_merge_pull_request"]
|
||||
OpType string `json:"op_type,omitempty"`
|
||||
|
||||
// ref name
|
||||
@@ -68,6 +70,10 @@ func (m *Activity) Validate(formats strfmt.Registry) error {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateOpType(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateActUser(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
@@ -98,6 +104,123 @@ func (m *Activity) validateCreated(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var activityTypeOpTypePropEnum []interface{}
|
||||
|
||||
func init() {
|
||||
var res []string
|
||||
if err := json.Unmarshal([]byte(`["create_repo","rename_repo","star_repo","watch_repo","commit_repo","create_issue","create_pull_request","transfer_repo","push_tag","comment_issue","merge_pull_request","close_issue","reopen_issue","close_pull_request","reopen_pull_request","delete_tag","delete_branch","mirror_sync_push","mirror_sync_create","mirror_sync_delete","approve_pull_request","reject_pull_request","comment_pull","publish_release","pull_review_dismissed","pull_request_ready_for_review","auto_merge_pull_request"]`), &res); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, v := range res {
|
||||
activityTypeOpTypePropEnum = append(activityTypeOpTypePropEnum, v)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
// ActivityOpTypeCreateRepo captures enum value "create_repo"
|
||||
ActivityOpTypeCreateRepo string = "create_repo"
|
||||
|
||||
// ActivityOpTypeRenameRepo captures enum value "rename_repo"
|
||||
ActivityOpTypeRenameRepo string = "rename_repo"
|
||||
|
||||
// ActivityOpTypeStarRepo captures enum value "star_repo"
|
||||
ActivityOpTypeStarRepo string = "star_repo"
|
||||
|
||||
// ActivityOpTypeWatchRepo captures enum value "watch_repo"
|
||||
ActivityOpTypeWatchRepo string = "watch_repo"
|
||||
|
||||
// ActivityOpTypeCommitRepo captures enum value "commit_repo"
|
||||
ActivityOpTypeCommitRepo string = "commit_repo"
|
||||
|
||||
// ActivityOpTypeCreateIssue captures enum value "create_issue"
|
||||
ActivityOpTypeCreateIssue string = "create_issue"
|
||||
|
||||
// ActivityOpTypeCreatePullRequest captures enum value "create_pull_request"
|
||||
ActivityOpTypeCreatePullRequest string = "create_pull_request"
|
||||
|
||||
// ActivityOpTypeTransferRepo captures enum value "transfer_repo"
|
||||
ActivityOpTypeTransferRepo string = "transfer_repo"
|
||||
|
||||
// ActivityOpTypePushTag captures enum value "push_tag"
|
||||
ActivityOpTypePushTag string = "push_tag"
|
||||
|
||||
// ActivityOpTypeCommentIssue captures enum value "comment_issue"
|
||||
ActivityOpTypeCommentIssue string = "comment_issue"
|
||||
|
||||
// ActivityOpTypeMergePullRequest captures enum value "merge_pull_request"
|
||||
ActivityOpTypeMergePullRequest string = "merge_pull_request"
|
||||
|
||||
// ActivityOpTypeCloseIssue captures enum value "close_issue"
|
||||
ActivityOpTypeCloseIssue string = "close_issue"
|
||||
|
||||
// ActivityOpTypeReopenIssue captures enum value "reopen_issue"
|
||||
ActivityOpTypeReopenIssue string = "reopen_issue"
|
||||
|
||||
// ActivityOpTypeClosePullRequest captures enum value "close_pull_request"
|
||||
ActivityOpTypeClosePullRequest string = "close_pull_request"
|
||||
|
||||
// ActivityOpTypeReopenPullRequest captures enum value "reopen_pull_request"
|
||||
ActivityOpTypeReopenPullRequest string = "reopen_pull_request"
|
||||
|
||||
// ActivityOpTypeDeleteTag captures enum value "delete_tag"
|
||||
ActivityOpTypeDeleteTag string = "delete_tag"
|
||||
|
||||
// ActivityOpTypeDeleteBranch captures enum value "delete_branch"
|
||||
ActivityOpTypeDeleteBranch string = "delete_branch"
|
||||
|
||||
// ActivityOpTypeMirrorSyncPush captures enum value "mirror_sync_push"
|
||||
ActivityOpTypeMirrorSyncPush string = "mirror_sync_push"
|
||||
|
||||
// ActivityOpTypeMirrorSyncCreate captures enum value "mirror_sync_create"
|
||||
ActivityOpTypeMirrorSyncCreate string = "mirror_sync_create"
|
||||
|
||||
// ActivityOpTypeMirrorSyncDelete captures enum value "mirror_sync_delete"
|
||||
ActivityOpTypeMirrorSyncDelete string = "mirror_sync_delete"
|
||||
|
||||
// ActivityOpTypeApprovePullRequest captures enum value "approve_pull_request"
|
||||
ActivityOpTypeApprovePullRequest string = "approve_pull_request"
|
||||
|
||||
// ActivityOpTypeRejectPullRequest captures enum value "reject_pull_request"
|
||||
ActivityOpTypeRejectPullRequest string = "reject_pull_request"
|
||||
|
||||
// ActivityOpTypeCommentPull captures enum value "comment_pull"
|
||||
ActivityOpTypeCommentPull string = "comment_pull"
|
||||
|
||||
// ActivityOpTypePublishRelease captures enum value "publish_release"
|
||||
ActivityOpTypePublishRelease string = "publish_release"
|
||||
|
||||
// ActivityOpTypePullReviewDismissed captures enum value "pull_review_dismissed"
|
||||
ActivityOpTypePullReviewDismissed string = "pull_review_dismissed"
|
||||
|
||||
// ActivityOpTypePullRequestReadyForReview captures enum value "pull_request_ready_for_review"
|
||||
ActivityOpTypePullRequestReadyForReview string = "pull_request_ready_for_review"
|
||||
|
||||
// ActivityOpTypeAutoMergePullRequest captures enum value "auto_merge_pull_request"
|
||||
ActivityOpTypeAutoMergePullRequest string = "auto_merge_pull_request"
|
||||
)
|
||||
|
||||
// prop value enum
|
||||
func (m *Activity) validateOpTypeEnum(path, location string, value string) error {
|
||||
if err := validate.EnumCase(path, location, value, activityTypeOpTypePropEnum, true); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Activity) validateOpType(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.OpType) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
// value enum
|
||||
if err := m.validateOpTypeEnum("op_type", "body", m.OpType); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Activity) validateActUser(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.ActUser) { // not required
|
||||
return nil
|
||||
|
||||
@@ -7,9 +7,12 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// AddCollaboratorOption AddCollaboratorOption options when adding a user as a collaborator of a repository
|
||||
@@ -18,11 +21,66 @@ import (
|
||||
type AddCollaboratorOption struct {
|
||||
|
||||
// permission
|
||||
// Enum: ["read","write","admin"]
|
||||
Permission string `json:"permission,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this add collaborator option
|
||||
func (m *AddCollaboratorOption) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validatePermission(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var addCollaboratorOptionTypePermissionPropEnum []interface{}
|
||||
|
||||
func init() {
|
||||
var res []string
|
||||
if err := json.Unmarshal([]byte(`["read","write","admin"]`), &res); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, v := range res {
|
||||
addCollaboratorOptionTypePermissionPropEnum = append(addCollaboratorOptionTypePermissionPropEnum, v)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
// AddCollaboratorOptionPermissionRead captures enum value "read"
|
||||
AddCollaboratorOptionPermissionRead string = "read"
|
||||
|
||||
// AddCollaboratorOptionPermissionWrite captures enum value "write"
|
||||
AddCollaboratorOptionPermissionWrite string = "write"
|
||||
|
||||
// AddCollaboratorOptionPermissionAdmin captures enum value "admin"
|
||||
AddCollaboratorOptionPermissionAdmin string = "admin"
|
||||
)
|
||||
|
||||
// prop value enum
|
||||
func (m *AddCollaboratorOption) validatePermissionEnum(path, location string, value string) error {
|
||||
if err := validate.EnumCase(path, location, value, addCollaboratorOptionTypePermissionPropEnum, true); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *AddCollaboratorOption) validatePermission(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Permission) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
// value enum
|
||||
if err := m.validatePermissionEnum("permission", "body", m.Permission); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ type BranchProtection struct {
|
||||
// approvals whitelist usernames
|
||||
ApprovalsWhitelistUsernames []string `json:"approvals_whitelist_username"`
|
||||
|
||||
// block admin merge override
|
||||
BlockAdminMergeOverride bool `json:"block_admin_merge_override,omitempty"`
|
||||
|
||||
// block on official review requests
|
||||
BlockOnOfficialReviewRequests bool `json:"block_on_official_review_requests,omitempty"`
|
||||
|
||||
@@ -47,6 +50,12 @@ type BranchProtection struct {
|
||||
// enable approvals whitelist
|
||||
EnableApprovalsWhitelist bool `json:"enable_approvals_whitelist,omitempty"`
|
||||
|
||||
// enable force push
|
||||
EnableForcePush bool `json:"enable_force_push,omitempty"`
|
||||
|
||||
// enable force push allowlist
|
||||
EnableForcePushAllowlist bool `json:"enable_force_push_allowlist,omitempty"`
|
||||
|
||||
// enable merge whitelist
|
||||
EnableMergeWhitelist bool `json:"enable_merge_whitelist,omitempty"`
|
||||
|
||||
@@ -59,6 +68,15 @@ type BranchProtection struct {
|
||||
// enable status check
|
||||
EnableStatusCheck bool `json:"enable_status_check,omitempty"`
|
||||
|
||||
// force push allowlist deploy keys
|
||||
ForcePushAllowlistDeployKeys bool `json:"force_push_allowlist_deploy_keys,omitempty"`
|
||||
|
||||
// force push allowlist teams
|
||||
ForcePushAllowlistTeams []string `json:"force_push_allowlist_teams"`
|
||||
|
||||
// force push allowlist usernames
|
||||
ForcePushAllowlistUsernames []string `json:"force_push_allowlist_usernames"`
|
||||
|
||||
// ignore stale approvals
|
||||
IgnoreStaleApprovals bool `json:"ignore_stale_approvals,omitempty"`
|
||||
|
||||
@@ -68,6 +86,9 @@ type BranchProtection struct {
|
||||
// merge whitelist usernames
|
||||
MergeWhitelistUsernames []string `json:"merge_whitelist_usernames"`
|
||||
|
||||
// priority
|
||||
Priority int64 `json:"priority,omitempty"`
|
||||
|
||||
// protected file patterns
|
||||
ProtectedFilePatterns string `json:"protected_file_patterns,omitempty"`
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ type CreateAccessTokenOption struct {
|
||||
Name *string `json:"name"`
|
||||
|
||||
// scopes
|
||||
// Example: ["all","read:activitypub","read:issue","write:misc","read:notification","read:organization","read:package","read:repository","read:user"]
|
||||
Scopes []string `json:"scopes"`
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ type CreateBranchProtectionOption struct {
|
||||
// approvals whitelist usernames
|
||||
ApprovalsWhitelistUsernames []string `json:"approvals_whitelist_username"`
|
||||
|
||||
// block admin merge override
|
||||
BlockAdminMergeOverride bool `json:"block_admin_merge_override,omitempty"`
|
||||
|
||||
// block on official review requests
|
||||
BlockOnOfficialReviewRequests bool `json:"block_on_official_review_requests,omitempty"`
|
||||
|
||||
@@ -41,6 +44,12 @@ type CreateBranchProtectionOption struct {
|
||||
// enable approvals whitelist
|
||||
EnableApprovalsWhitelist bool `json:"enable_approvals_whitelist,omitempty"`
|
||||
|
||||
// enable force push
|
||||
EnableForcePush bool `json:"enable_force_push,omitempty"`
|
||||
|
||||
// enable force push allowlist
|
||||
EnableForcePushAllowlist bool `json:"enable_force_push_allowlist,omitempty"`
|
||||
|
||||
// enable merge whitelist
|
||||
EnableMergeWhitelist bool `json:"enable_merge_whitelist,omitempty"`
|
||||
|
||||
@@ -53,6 +62,15 @@ type CreateBranchProtectionOption struct {
|
||||
// enable status check
|
||||
EnableStatusCheck bool `json:"enable_status_check,omitempty"`
|
||||
|
||||
// force push allowlist deploy keys
|
||||
ForcePushAllowlistDeployKeys bool `json:"force_push_allowlist_deploy_keys,omitempty"`
|
||||
|
||||
// force push allowlist teams
|
||||
ForcePushAllowlistTeams []string `json:"force_push_allowlist_teams"`
|
||||
|
||||
// force push allowlist usernames
|
||||
ForcePushAllowlistUsernames []string `json:"force_push_allowlist_usernames"`
|
||||
|
||||
// ignore stale approvals
|
||||
IgnoreStaleApprovals bool `json:"ignore_stale_approvals,omitempty"`
|
||||
|
||||
@@ -62,6 +80,9 @@ type CreateBranchProtectionOption struct {
|
||||
// merge whitelist usernames
|
||||
MergeWhitelistUsernames []string `json:"merge_whitelist_usernames"`
|
||||
|
||||
// priority
|
||||
Priority int64 `json:"priority,omitempty"`
|
||||
|
||||
// protected file patterns
|
||||
ProtectedFilePatterns string `json:"protected_file_patterns,omitempty"`
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ type CreateOAuth2ApplicationOptions struct {
|
||||
|
||||
// redirect u r is
|
||||
RedirectURIs []string `json:"redirect_uris"`
|
||||
|
||||
// skip secondary authorization
|
||||
SkipSecondaryAuthorization bool `json:"skip_secondary_authorization,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this create o auth2 application options
|
||||
|
||||
@@ -44,6 +44,12 @@ type CreatePullRequestOption struct {
|
||||
// milestone
|
||||
Milestone int64 `json:"milestone,omitempty"`
|
||||
|
||||
// reviewers
|
||||
Reviewers []string `json:"reviewers"`
|
||||
|
||||
// team reviewers
|
||||
TeamReviewers []string `json:"team_reviewers"`
|
||||
|
||||
// title
|
||||
Title string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// CreateTagProtectionOption CreateTagProtectionOption options for creating a tag protection
|
||||
//
|
||||
// swagger:model CreateTagProtectionOption
|
||||
type CreateTagProtectionOption struct {
|
||||
|
||||
// name pattern
|
||||
NamePattern string `json:"name_pattern,omitempty"`
|
||||
|
||||
// whitelist teams
|
||||
WhitelistTeams []string `json:"whitelist_teams"`
|
||||
|
||||
// whitelist usernames
|
||||
WhitelistUsernames []string `json:"whitelist_usernames"`
|
||||
}
|
||||
|
||||
// Validate validates this create tag protection option
|
||||
func (m *CreateTagProtectionOption) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this create tag protection option based on context it is used
|
||||
func (m *CreateTagProtectionOption) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *CreateTagProtectionOption) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *CreateTagProtectionOption) UnmarshalBinary(b []byte) error {
|
||||
var res CreateTagProtectionOption
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -23,6 +23,9 @@ type EditBranchProtectionOption struct {
|
||||
// approvals whitelist usernames
|
||||
ApprovalsWhitelistUsernames []string `json:"approvals_whitelist_username"`
|
||||
|
||||
// block admin merge override
|
||||
BlockAdminMergeOverride bool `json:"block_admin_merge_override,omitempty"`
|
||||
|
||||
// block on official review requests
|
||||
BlockOnOfficialReviewRequests bool `json:"block_on_official_review_requests,omitempty"`
|
||||
|
||||
@@ -38,6 +41,12 @@ type EditBranchProtectionOption struct {
|
||||
// enable approvals whitelist
|
||||
EnableApprovalsWhitelist bool `json:"enable_approvals_whitelist,omitempty"`
|
||||
|
||||
// enable force push
|
||||
EnableForcePush bool `json:"enable_force_push,omitempty"`
|
||||
|
||||
// enable force push allowlist
|
||||
EnableForcePushAllowlist bool `json:"enable_force_push_allowlist,omitempty"`
|
||||
|
||||
// enable merge whitelist
|
||||
EnableMergeWhitelist bool `json:"enable_merge_whitelist,omitempty"`
|
||||
|
||||
@@ -50,6 +59,15 @@ type EditBranchProtectionOption struct {
|
||||
// enable status check
|
||||
EnableStatusCheck bool `json:"enable_status_check,omitempty"`
|
||||
|
||||
// force push allowlist deploy keys
|
||||
ForcePushAllowlistDeployKeys bool `json:"force_push_allowlist_deploy_keys,omitempty"`
|
||||
|
||||
// force push allowlist teams
|
||||
ForcePushAllowlistTeams []string `json:"force_push_allowlist_teams"`
|
||||
|
||||
// force push allowlist usernames
|
||||
ForcePushAllowlistUsernames []string `json:"force_push_allowlist_usernames"`
|
||||
|
||||
// ignore stale approvals
|
||||
IgnoreStaleApprovals bool `json:"ignore_stale_approvals,omitempty"`
|
||||
|
||||
@@ -59,6 +77,9 @@ type EditBranchProtectionOption struct {
|
||||
// merge whitelist usernames
|
||||
MergeWhitelistUsernames []string `json:"merge_whitelist_usernames"`
|
||||
|
||||
// priority
|
||||
Priority int64 `json:"priority,omitempty"`
|
||||
|
||||
// protected file patterns
|
||||
ProtectedFilePatterns string `json:"protected_file_patterns,omitempty"`
|
||||
|
||||
|
||||
56
common/gitea-generated/models/edit_tag_protection_option.go
Normal file
56
common/gitea-generated/models/edit_tag_protection_option.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// EditTagProtectionOption EditTagProtectionOption options for editing a tag protection
|
||||
//
|
||||
// swagger:model EditTagProtectionOption
|
||||
type EditTagProtectionOption struct {
|
||||
|
||||
// name pattern
|
||||
NamePattern string `json:"name_pattern,omitempty"`
|
||||
|
||||
// whitelist teams
|
||||
WhitelistTeams []string `json:"whitelist_teams"`
|
||||
|
||||
// whitelist usernames
|
||||
WhitelistUsernames []string `json:"whitelist_usernames"`
|
||||
}
|
||||
|
||||
// Validate validates this edit tag protection option
|
||||
func (m *EditTagProtectionOption) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this edit tag protection option based on context it is used
|
||||
func (m *EditTagProtectionOption) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *EditTagProtectionOption) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *EditTagProtectionOption) UnmarshalBinary(b []byte) error {
|
||||
var res EditTagProtectionOption
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -40,8 +40,11 @@ type IssueTemplate struct {
|
||||
// title
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// assignees
|
||||
Assignees IssueTemplateStringSlice `json:"assignees,omitempty"`
|
||||
|
||||
// labels
|
||||
Labels IssueTemplateLabels `json:"labels,omitempty"`
|
||||
Labels IssueTemplateStringSlice `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this issue template
|
||||
@@ -52,6 +55,10 @@ func (m *IssueTemplate) Validate(formats strfmt.Registry) error {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateAssignees(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateLabels(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
@@ -88,6 +95,23 @@ func (m *IssueTemplate) validateFields(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *IssueTemplate) validateAssignees(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Assignees) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := m.Assignees.Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("assignees")
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("assignees")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *IssueTemplate) validateLabels(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Labels) { // not required
|
||||
return nil
|
||||
@@ -113,6 +137,10 @@ func (m *IssueTemplate) ContextValidate(ctx context.Context, formats strfmt.Regi
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.contextValidateAssignees(ctx, formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.contextValidateLabels(ctx, formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
@@ -148,6 +176,20 @@ func (m *IssueTemplate) contextValidateFields(ctx context.Context, formats strfm
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *IssueTemplate) contextValidateAssignees(ctx context.Context, formats strfmt.Registry) error {
|
||||
|
||||
if err := m.Assignees.ContextValidate(ctx, formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("assignees")
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("assignees")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *IssueTemplate) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {
|
||||
|
||||
if err := m.Labels.ContextValidate(ctx, formats); err != nil {
|
||||
|
||||
27
common/gitea-generated/models/issue_template_string_slice.go
Normal file
27
common/gitea-generated/models/issue_template_string_slice.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// IssueTemplateStringSlice issue template string slice
|
||||
//
|
||||
// swagger:model IssueTemplateStringSlice
|
||||
type IssueTemplateStringSlice []string
|
||||
|
||||
// Validate validates this issue template string slice
|
||||
func (m IssueTemplateStringSlice) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this issue template string slice based on context it is used
|
||||
func (m IssueTemplateStringSlice) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
@@ -23,7 +23,7 @@ type MarkdownOption struct {
|
||||
// in: body
|
||||
Context string `json:"Context,omitempty"`
|
||||
|
||||
// Mode to render (comment, gfm, markdown)
|
||||
// Mode to render (markdown, comment, wiki, file)
|
||||
//
|
||||
// in: body
|
||||
Mode string `json:"Mode,omitempty"`
|
||||
@@ -33,8 +33,9 @@ type MarkdownOption struct {
|
||||
// in: body
|
||||
Text string `json:"Text,omitempty"`
|
||||
|
||||
// Is it a wiki page ?
|
||||
// Is it a wiki page? (use mode=wiki instead)
|
||||
//
|
||||
// Deprecated: true
|
||||
// in: body
|
||||
Wiki bool `json:"Wiki,omitempty"`
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ type MarkupOption struct {
|
||||
// in: body
|
||||
FilePath string `json:"FilePath,omitempty"`
|
||||
|
||||
// Mode to render (comment, gfm, markdown, file)
|
||||
// Mode to render (markdown, comment, wiki, file)
|
||||
//
|
||||
// in: body
|
||||
Mode string `json:"Mode,omitempty"`
|
||||
@@ -38,8 +38,9 @@ type MarkupOption struct {
|
||||
// in: body
|
||||
Text string `json:"Text,omitempty"`
|
||||
|
||||
// Is it a wiki page ?
|
||||
// Is it a wiki page? (use mode=wiki instead)
|
||||
//
|
||||
// Deprecated: true
|
||||
// in: body
|
||||
Wiki bool `json:"Wiki,omitempty"`
|
||||
}
|
||||
|
||||
50
common/gitea-generated/models/merge_upstream_request.go
Normal file
50
common/gitea-generated/models/merge_upstream_request.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// MergeUpstreamRequest merge upstream request
|
||||
//
|
||||
// swagger:model MergeUpstreamRequest
|
||||
type MergeUpstreamRequest struct {
|
||||
|
||||
// branch
|
||||
Branch string `json:"branch,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this merge upstream request
|
||||
func (m *MergeUpstreamRequest) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this merge upstream request based on context it is used
|
||||
func (m *MergeUpstreamRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *MergeUpstreamRequest) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *MergeUpstreamRequest) UnmarshalBinary(b []byte) error {
|
||||
var res MergeUpstreamRequest
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
50
common/gitea-generated/models/merge_upstream_response.go
Normal file
50
common/gitea-generated/models/merge_upstream_response.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// MergeUpstreamResponse merge upstream response
|
||||
//
|
||||
// swagger:model MergeUpstreamResponse
|
||||
type MergeUpstreamResponse struct {
|
||||
|
||||
// merge style
|
||||
MergeStyle string `json:"merge_type,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this merge upstream response
|
||||
func (m *MergeUpstreamResponse) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this merge upstream response based on context it is used
|
||||
func (m *MergeUpstreamResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *MergeUpstreamResponse) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *MergeUpstreamResponse) UnmarshalBinary(b []byte) error {
|
||||
var res MergeUpstreamResponse
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -21,6 +21,12 @@ import (
|
||||
// swagger:model MigrateRepoOptions
|
||||
type MigrateRepoOptions struct {
|
||||
|
||||
// a w s access key ID
|
||||
AWSAccessKeyID string `json:"aws_access_key_id,omitempty"`
|
||||
|
||||
// a w s secret access key
|
||||
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
|
||||
|
||||
// auth password
|
||||
AuthPassword string `json:"auth_password,omitempty"`
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ type OAuth2Application struct {
|
||||
|
||||
// redirect u r is
|
||||
RedirectURIs []string `json:"redirect_uris"`
|
||||
|
||||
// skip secondary authorization
|
||||
SkipSecondaryAuthorization bool `json:"skip_secondary_authorization,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this o auth2 application
|
||||
|
||||
@@ -99,6 +99,9 @@ type PullRequest struct {
|
||||
// requested reviewers
|
||||
RequestedReviewers []*User `json:"requested_reviewers"`
|
||||
|
||||
// requested reviewers teams
|
||||
RequestedReviewersTeams []*Team `json:"requested_reviewers_teams"`
|
||||
|
||||
// number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)
|
||||
ReviewComments int64 `json:"review_comments,omitempty"`
|
||||
|
||||
@@ -166,6 +169,10 @@ func (m *PullRequest) Validate(formats strfmt.Registry) error {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateRequestedReviewersTeams(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateUpdated(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
@@ -330,6 +337,32 @@ func (m *PullRequest) validateRequestedReviewers(formats strfmt.Registry) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PullRequest) validateRequestedReviewersTeams(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.RequestedReviewersTeams) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < len(m.RequestedReviewersTeams); i++ {
|
||||
if swag.IsZero(m.RequestedReviewersTeams[i]) { // not required
|
||||
continue
|
||||
}
|
||||
|
||||
if m.RequestedReviewersTeams[i] != nil {
|
||||
if err := m.RequestedReviewersTeams[i].Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("requested_reviewers_teams" + "." + strconv.Itoa(i))
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("requested_reviewers_teams" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PullRequest) validateUpdated(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Updated) { // not required
|
||||
return nil
|
||||
@@ -489,6 +522,10 @@ func (m *PullRequest) ContextValidate(ctx context.Context, formats strfmt.Regist
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.contextValidateRequestedReviewersTeams(ctx, formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.contextValidateAssignee(ctx, formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
@@ -598,6 +635,31 @@ func (m *PullRequest) contextValidateRequestedReviewers(ctx context.Context, for
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PullRequest) contextValidateRequestedReviewersTeams(ctx context.Context, formats strfmt.Registry) error {
|
||||
|
||||
for i := 0; i < len(m.RequestedReviewersTeams); i++ {
|
||||
|
||||
if m.RequestedReviewersTeams[i] != nil {
|
||||
|
||||
if swag.IsZero(m.RequestedReviewersTeams[i]) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := m.RequestedReviewersTeams[i].ContextValidate(ctx, formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("requested_reviewers_teams" + "." + strconv.Itoa(i))
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("requested_reviewers_teams" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PullRequest) contextValidateAssignee(ctx context.Context, formats strfmt.Registry) error {
|
||||
|
||||
if m.Assignee != nil {
|
||||
|
||||
@@ -23,6 +23,9 @@ type Repository struct {
|
||||
// allow fast forward only
|
||||
AllowFastForwardOnly bool `json:"allow_fast_forward_only_merge,omitempty"`
|
||||
|
||||
// allow manual merge
|
||||
AllowManualMerge bool `json:"allow_manual_merge,omitempty"`
|
||||
|
||||
// allow merge
|
||||
AllowMerge bool `json:"allow_merge_commits,omitempty"`
|
||||
|
||||
@@ -45,6 +48,9 @@ type Repository struct {
|
||||
// Format: date-time
|
||||
ArchivedAt strfmt.DateTime `json:"archived_at,omitempty"`
|
||||
|
||||
// autodetect manual merge
|
||||
AutodetectManualMerge bool `json:"autodetect_manual_merge,omitempty"`
|
||||
|
||||
// avatar URL
|
||||
AvatarURL string `json:"avatar_url,omitempty"`
|
||||
|
||||
@@ -121,6 +127,9 @@ type Repository struct {
|
||||
// languages URL
|
||||
LanguagesURL string `json:"languages_url,omitempty"`
|
||||
|
||||
// licenses
|
||||
Licenses []string `json:"licenses"`
|
||||
|
||||
// link
|
||||
Link string `json:"link,omitempty"`
|
||||
|
||||
@@ -171,6 +180,9 @@ type Repository struct {
|
||||
// template
|
||||
Template bool `json:"template,omitempty"`
|
||||
|
||||
// topics
|
||||
Topics []string `json:"topics"`
|
||||
|
||||
// URL
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
|
||||
106
common/gitea-generated/models/tag_protection.go
Normal file
106
common/gitea-generated/models/tag_protection.go
Normal file
@@ -0,0 +1,106 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// TagProtection TagProtection represents a tag protection
|
||||
//
|
||||
// swagger:model TagProtection
|
||||
type TagProtection struct {
|
||||
|
||||
// created
|
||||
// Format: date-time
|
||||
Created strfmt.DateTime `json:"created_at,omitempty"`
|
||||
|
||||
// ID
|
||||
ID int64 `json:"id,omitempty"`
|
||||
|
||||
// name pattern
|
||||
NamePattern string `json:"name_pattern,omitempty"`
|
||||
|
||||
// updated
|
||||
// Format: date-time
|
||||
Updated strfmt.DateTime `json:"updated_at,omitempty"`
|
||||
|
||||
// whitelist teams
|
||||
WhitelistTeams []string `json:"whitelist_teams"`
|
||||
|
||||
// whitelist usernames
|
||||
WhitelistUsernames []string `json:"whitelist_usernames"`
|
||||
}
|
||||
|
||||
// Validate validates this tag protection
|
||||
func (m *TagProtection) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateCreated(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateUpdated(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *TagProtection) validateCreated(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Created) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validate.FormatOf("created_at", "body", "date-time", m.Created.String(), formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *TagProtection) validateUpdated(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Updated) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validate.FormatOf("updated_at", "body", "date-time", m.Updated.String(), formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this tag protection based on context it is used
|
||||
func (m *TagProtection) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *TagProtection) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *TagProtection) UnmarshalBinary(b []byte) error {
|
||||
var res TagProtection
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// UpdateBranchProtectionPriories UpdateBranchProtectionPriories a list to update the branch protection rule priorities
|
||||
//
|
||||
// swagger:model UpdateBranchProtectionPriories
|
||||
type UpdateBranchProtectionPriories struct {
|
||||
|
||||
// i ds
|
||||
IDs []int64 `json:"ids"`
|
||||
}
|
||||
|
||||
// Validate validates this update branch protection priories
|
||||
func (m *UpdateBranchProtectionPriories) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this update branch protection priories based on context it is used
|
||||
func (m *UpdateBranchProtectionPriories) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *UpdateBranchProtectionPriories) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *UpdateBranchProtectionPriories) UnmarshalBinary(b []byte) error {
|
||||
var res UpdateBranchProtectionPriories
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
71
common/gitea-generated/models/update_branch_repo_option.go
Normal file
71
common/gitea-generated/models/update_branch_repo_option.go
Normal file
@@ -0,0 +1,71 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// UpdateBranchRepoOption UpdateBranchRepoOption options when updating a branch in a repository
|
||||
//
|
||||
// swagger:model UpdateBranchRepoOption
|
||||
type UpdateBranchRepoOption struct {
|
||||
|
||||
// New branch name
|
||||
// Required: true
|
||||
Name *string `json:"name"`
|
||||
}
|
||||
|
||||
// Validate validates this update branch repo option
|
||||
func (m *UpdateBranchRepoOption) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateName(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UpdateBranchRepoOption) validateName(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("name", "body", m.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this update branch repo option based on context it is used
|
||||
func (m *UpdateBranchRepoOption) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *UpdateBranchRepoOption) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *UpdateBranchRepoOption) UnmarshalBinary(b []byte) error {
|
||||
var res UpdateBranchRepoOption
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -20,18 +20,21 @@ package common
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"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/issue"
|
||||
"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"
|
||||
@@ -63,6 +66,18 @@ const (
|
||||
ReviewStateUnknown models.ReviewStateType = ""
|
||||
)
|
||||
|
||||
type GiteaTimelineFetcher interface {
|
||||
GetTimeline(org, repo string, idx int64) ([]*models.TimelineComment, error)
|
||||
}
|
||||
|
||||
type GiteaComment interface {
|
||||
AddComment(pr *models.PullRequest, comment string) error
|
||||
}
|
||||
|
||||
type GiteaSetRepoOptions interface {
|
||||
SetRepoOptions(owner, repo string, manual_merge bool) (*models.Repository, error)
|
||||
}
|
||||
|
||||
type GiteaMaintainershipReader interface {
|
||||
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, string, error)
|
||||
FetchMaintainershipDirFile(org, prjGit, branch, pkg string) ([]byte, string, error)
|
||||
@@ -70,20 +85,43 @@ type GiteaMaintainershipReader interface {
|
||||
|
||||
type GiteaPRFetcher interface {
|
||||
GetPullRequest(org, project string, num int64) (*models.PullRequest, error)
|
||||
GetAssociatedPrjGitPR(prjGitOrg, prjGitRepo, refOrg, refRepo string, Index int64) (*models.PullRequest, error)
|
||||
}
|
||||
|
||||
type GiteaPRUpdater interface {
|
||||
UpdatePullRequest(org, repo string, num int64, options *models.EditPullRequestOption) (*models.PullRequest, error)
|
||||
}
|
||||
|
||||
type GiteaPRTimelineFetcher interface {
|
||||
GiteaPRFetcher
|
||||
GiteaTimelineFetcher
|
||||
}
|
||||
|
||||
type GiteaCommitFetcher interface {
|
||||
GetCommit(org, repo, sha string) (*models.Commit, error)
|
||||
}
|
||||
|
||||
type GiteaReviewFetcher interface {
|
||||
GetPullRequestReviews(org, project string, PRnum int64) ([]*models.PullReview, error)
|
||||
}
|
||||
|
||||
type GiteaPRChecker interface {
|
||||
type GiteaCommentFetcher interface {
|
||||
GetIssueComments(org, project string, issueNo int64) ([]*models.Comment, error)
|
||||
}
|
||||
|
||||
type GiteaReviewTimelineFetcher interface {
|
||||
GiteaReviewFetcher
|
||||
GiteaTimelineFetcher
|
||||
}
|
||||
|
||||
type GiteaPRChecker interface {
|
||||
GiteaReviewTimelineFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaMaintainershipReader
|
||||
}
|
||||
|
||||
type GiteaReviewFetcherAndRequester interface {
|
||||
GiteaReviewFetcher
|
||||
GiteaReviewTimelineFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaReviewRequester
|
||||
}
|
||||
|
||||
@@ -91,6 +129,10 @@ type GiteaReviewRequester interface {
|
||||
RequestReviews(pr *models.PullRequest, reviewer ...string) ([]*models.PullReview, error)
|
||||
}
|
||||
|
||||
type GiteaReviewUnrequester interface {
|
||||
UnrequestReview(org, repo string, id int64, reviwers ...string) error
|
||||
}
|
||||
|
||||
type GiteaReviewer interface {
|
||||
AddReviewComment(pr *models.PullRequest, state models.ReviewStateType, comment string) (*models.PullReview, error)
|
||||
}
|
||||
@@ -99,25 +141,55 @@ type GiteaRepoFetcher interface {
|
||||
GetRepository(org, repo string) (*models.Repository, error)
|
||||
}
|
||||
|
||||
type GiteaFileContentReader interface {
|
||||
GetRepositoryFileContent(org, repo, hash, path string) ([]byte, string, error)
|
||||
}
|
||||
|
||||
const (
|
||||
CommitStatus_Pending = "pending"
|
||||
CommitStatus_Success = "success"
|
||||
CommitStatus_Fail = "failure"
|
||||
CommitStatus_Error = "error"
|
||||
)
|
||||
|
||||
type GiteaCommitStatusSetter interface {
|
||||
SetCommitStatus(org, repo, hash string, status *models.CommitStatus) (*models.CommitStatus, error)
|
||||
}
|
||||
|
||||
type GiteaCommitStatusGetter interface {
|
||||
GetCommitStatus(org, repo, hash string) ([]*models.CommitStatus, error)
|
||||
}
|
||||
|
||||
type Gitea interface {
|
||||
GiteaComment
|
||||
GiteaRepoFetcher
|
||||
GiteaReviewRequester
|
||||
GiteaReviewUnrequester
|
||||
GiteaReviewer
|
||||
GiteaPRFetcher
|
||||
GiteaPRUpdater
|
||||
GiteaCommitFetcher
|
||||
GiteaReviewFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaTimelineFetcher
|
||||
GiteaMaintainershipReader
|
||||
GiteaFileContentReader
|
||||
GiteaCommitStatusGetter
|
||||
GiteaCommitStatusSetter
|
||||
GiteaSetRepoOptions
|
||||
GiteaTimelineFetcher
|
||||
|
||||
GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error)
|
||||
GetNotifications(Type string, since *time.Time) ([]*models.NotificationThread, error)
|
||||
GetDoneNotifications(Type string, page int64) ([]*models.NotificationThread, error)
|
||||
SetNotificationRead(notificationId int64) error
|
||||
GetOrganization(orgName string) (*models.Organization, error)
|
||||
GetOrganizationRepositories(orgName string) ([]*models.Repository, error)
|
||||
CreateRepositoryIfNotExist(git Git, org, repoName string) (*models.Repository, error)
|
||||
CreatePullRequestIfNotExist(repo *models.Repository, srcId, targetId, title, body string) (*models.PullRequest, error)
|
||||
GetAssociatedPrjGitPR(prjGitOrg, prjGitRepo, refOrg, refRepo string, Index int64) (*models.PullRequest, error)
|
||||
GetRepositoryFileContent(org, repo, hash, path string) ([]byte, string, error)
|
||||
GetPullRequestFileContent(pr *models.PullRequest, path string) ([]byte, string, error)
|
||||
GetRecentPullRequests(org, repo string) ([]*models.PullRequest, error)
|
||||
GetRecentPullRequests(org, repo, branch string) ([]*models.PullRequest, error)
|
||||
GetRecentCommits(org, repo, branch string, commitNo int64) ([]*models.Commit, error)
|
||||
GetPullRequests(org, project string) ([]*models.PullRequest, error)
|
||||
|
||||
GetCurrentUser() (*models.User, error)
|
||||
}
|
||||
@@ -127,10 +199,15 @@ type GiteaTransport struct {
|
||||
client *apiclient.GiteaAPI
|
||||
}
|
||||
|
||||
func AllocateGiteaTransport(host string) Gitea {
|
||||
func AllocateGiteaTransport(giteaUrl string) Gitea {
|
||||
var r GiteaTransport
|
||||
|
||||
r.transport = transport.New(host, apiclient.DefaultBasePath, [](string){"https"})
|
||||
url, err := url.Parse(giteaUrl)
|
||||
if err != nil {
|
||||
log.Panicln("Failed to parse gitea url:", err)
|
||||
}
|
||||
|
||||
r.transport = transport.New(url.Host, apiclient.DefaultBasePath, [](string){url.Scheme})
|
||||
r.transport.DefaultAuthentication = transport.BearerToken(giteaToken)
|
||||
|
||||
r.client = apiclient.New(r.transport, nil)
|
||||
@@ -159,9 +236,103 @@ func (gitea *GiteaTransport) GetPullRequest(org, project string, num int64) (*mo
|
||||
return pr.Payload, err
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) UpdatePullRequest(org, repo string, num int64, options *models.EditPullRequestOption) (*models.PullRequest, error) {
|
||||
pr, err := gitea.client.Repository.RepoEditPullRequest(
|
||||
repository.NewRepoEditPullRequestParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithIndex(num).
|
||||
WithBody(options),
|
||||
gitea.transport.DefaultAuthentication,
|
||||
)
|
||||
|
||||
return pr.Payload, err
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetPullRequests(org, repo string) ([]*models.PullRequest, error) {
|
||||
var page, limit int64
|
||||
|
||||
prs := make([]*models.PullRequest, 0)
|
||||
limit = 20
|
||||
state := "open"
|
||||
|
||||
for {
|
||||
page++
|
||||
req, err := gitea.client.Repository.RepoListPullRequests(
|
||||
repository.
|
||||
NewRepoListPullRequestsParams().
|
||||
WithDefaults().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithState(&state).
|
||||
WithPage(&page).
|
||||
WithLimit(&limit),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot fetch PR list for %s / %s : %w", org, repo, err)
|
||||
}
|
||||
|
||||
prs = slices.Concat(prs, req.Payload)
|
||||
if len(req.Payload) < int(limit) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return prs, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetCommitStatus(org, repo, hash string) ([]*models.CommitStatus, error) {
|
||||
page := int64(1)
|
||||
limit := int64(10)
|
||||
var res []*models.CommitStatus
|
||||
|
||||
for {
|
||||
r, err := gitea.client.Repository.RepoListStatuses(
|
||||
repository.NewRepoListStatusesParams().WithDefaults().WithOwner(org).WithRepo(repo).WithSha(hash).WithPage(&page).WithLimit(&limit),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res = append(res, r.Payload...)
|
||||
if len(r.Payload) < int(limit) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) SetCommitStatus(org, repo, hash string, status *models.CommitStatus) (*models.CommitStatus, error) {
|
||||
res, err := gitea.client.Repository.RepoCreateStatus(
|
||||
repository.NewRepoCreateStatusParams().
|
||||
WithDefaults().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithSha(hash).
|
||||
WithBody(&models.CreateStatusOption{
|
||||
TargetURL: status.TargetURL,
|
||||
Description: status.Description,
|
||||
Context: status.Context,
|
||||
State: models.CommitStatusState(status.Status),
|
||||
}),
|
||||
gitea.transport.DefaultAuthentication,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.Payload, err
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetRepository(org, pkg string) (*models.Repository, error) {
|
||||
repo, err := gitea.client.Repository.RepoGet(repository.NewRepoGetParams().WithDefaults().WithOwner(org).WithRepo(pkg), gitea.transport.DefaultAuthentication)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *repository.RepoGetNotFound:
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -199,25 +370,116 @@ func (gitea *GiteaTransport) GetPullRequestReviews(org, project string, PRnum in
|
||||
return allReviews, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error) {
|
||||
bigLimit := int64(100000)
|
||||
func (gitea *GiteaTransport) GetCommit(org, repo, sha string) (*models.Commit, error) {
|
||||
f := false
|
||||
|
||||
params := notification.NewNotifyGetListParams().
|
||||
WithDefaults().
|
||||
WithSubjectType([]string{"Pull"}).
|
||||
WithStatusTypes([]string{"unread"}).
|
||||
WithLimit(&bigLimit)
|
||||
r, err := gitea.client.Repository.RepoGetSingleCommit(
|
||||
repository.NewRepoGetSingleCommitParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithSha(sha).
|
||||
WithStat(&f).
|
||||
WithFiles(&f).
|
||||
WithVerification(&f),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if since != nil {
|
||||
s := strfmt.DateTime(*since)
|
||||
params.SetSince(&s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.Payload, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetIssueComments(org, project string, issueNo int64) ([]*models.Comment, error) {
|
||||
// limit := int64(20)
|
||||
// var page int64
|
||||
// var allComments []*models.Comment
|
||||
|
||||
// for {
|
||||
c, err := gitea.client.Issue.IssueGetComments(
|
||||
issue.NewIssueGetCommentsParams().
|
||||
WithDefaults().
|
||||
WithOwner(org).
|
||||
WithRepo(project).
|
||||
WithIndex(issueNo),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
list, err := gitea.client.Notification.NotifyGetList(params, gitea.transport.DefaultAuthentication)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.Payload, nil
|
||||
// if len(c.Payload) < int(limit)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) SetRepoOptions(owner, repo string, manual_merge bool) (*models.Repository, error) {
|
||||
ok, err := gitea.client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(owner).WithRepo(repo).WithBody(
|
||||
&models.EditRepoOption{
|
||||
AllowManualMerge: manual_merge,
|
||||
AutodetectManualMerge: manual_merge,
|
||||
}), gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ok.Payload, err
|
||||
}
|
||||
|
||||
const (
|
||||
GiteaNotificationType_Pull = "Pull"
|
||||
)
|
||||
|
||||
func (gitea *GiteaTransport) GetNotifications(Type string, since *time.Time) ([]*models.NotificationThread, error) {
|
||||
bigLimit := int64(20)
|
||||
ret := make([]*models.NotificationThread, 0, 100)
|
||||
|
||||
for page := int64(1); ; page++ {
|
||||
params := notification.NewNotifyGetListParams().
|
||||
WithDefaults().
|
||||
WithSubjectType([]string{Type}).
|
||||
WithStatusTypes([]string{"unread"}).
|
||||
WithLimit(&bigLimit).
|
||||
WithPage(&page)
|
||||
|
||||
if since != nil {
|
||||
s := strfmt.DateTime(*since)
|
||||
params.SetSince(&s)
|
||||
}
|
||||
|
||||
list, err := gitea.client.Notification.NotifyGetList(params, gitea.transport.DefaultAuthentication)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret = slices.Concat(ret, list.Payload)
|
||||
if len(list.Payload) < int(bigLimit) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetDoneNotifications(Type string, page int64) ([]*models.NotificationThread, error) {
|
||||
limit := int64(20)
|
||||
t := true
|
||||
|
||||
if page <= 0 {
|
||||
return nil, fmt.Errorf("Page is 1-base positive int...")
|
||||
}
|
||||
list, err := gitea.client.Notification.NotifyGetList(
|
||||
notification.NewNotifyGetListParams().
|
||||
WithAll(&t).
|
||||
WithSubjectType([]string{Type}).
|
||||
WithStatusTypes([]string{"read"}).
|
||||
WithLimit(&limit).
|
||||
WithPage(&page),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list.Payload, nil
|
||||
}
|
||||
|
||||
@@ -274,6 +536,7 @@ func (gitea *GiteaTransport) GetOrganizationRepositories(orgName string) ([]*mod
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) CreateRepositoryIfNotExist(git Git, org, repoName string) (*models.Repository, error) {
|
||||
log.Println(org, repoName)
|
||||
repo, err := gitea.client.Repository.RepoGet(
|
||||
repository.NewRepoGetParams().WithDefaults().WithOwner(org).WithRepo(repoName),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
@@ -281,6 +544,7 @@ func (gitea *GiteaTransport) CreateRepositoryIfNotExist(git Git, org, repoName s
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *repository.RepoGetNotFound:
|
||||
log.Println("not found", err)
|
||||
repo, err := gitea.client.Organization.CreateOrgRepo(
|
||||
organization.NewCreateOrgRepoParams().WithDefaults().WithBody(
|
||||
&models.CreateRepoOption{
|
||||
@@ -339,14 +603,14 @@ func (gitea *GiteaTransport) CreateRepositoryIfNotExist(git Git, org, repoName s
|
||||
|
||||
func (gitea *GiteaTransport) CreatePullRequestIfNotExist(repo *models.Repository, srcId, targetId, title, body string) (*models.PullRequest, error) {
|
||||
prOptions := models.CreatePullRequestOption{
|
||||
Base: repo.DefaultBranch,
|
||||
Base: targetId,
|
||||
Head: srcId,
|
||||
Title: title,
|
||||
Body: body,
|
||||
}
|
||||
|
||||
if pr, err := gitea.client.Repository.RepoGetPullRequestByBaseHead(
|
||||
repository.NewRepoGetPullRequestByBaseHeadParams().WithOwner(repo.Owner.UserName).WithRepo(repo.Name).WithBase(repo.DefaultBranch).WithHead(srcId),
|
||||
repository.NewRepoGetPullRequestByBaseHeadParams().WithOwner(repo.Owner.UserName).WithRepo(repo.Name).WithBase(targetId).WithHead(srcId),
|
||||
gitea.transport.DefaultAuthentication,
|
||||
); err == nil {
|
||||
return pr.Payload, nil
|
||||
@@ -369,46 +633,6 @@ func (gitea *GiteaTransport) CreatePullRequestIfNotExist(repo *models.Repository
|
||||
return pr.GetPayload(), nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetAssociatedPrjGitPR(prjGitOrg, prjGitRepo, refOrg, refRepo string, Index int64) (*models.PullRequest, error) {
|
||||
var page int64
|
||||
state := "open"
|
||||
for {
|
||||
page++
|
||||
prs, err := gitea.client.Repository.RepoListPullRequests(
|
||||
repository.
|
||||
NewRepoListPullRequestsParams().
|
||||
WithDefaults().
|
||||
WithOwner(prjGitOrg).
|
||||
WithRepo(prjGitRepo).
|
||||
WithState(&state).
|
||||
WithPage(&page),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot fetch PR list for %s / %s : %w", prjGitOrg, prjGitRepo, err)
|
||||
}
|
||||
|
||||
prLine := fmt.Sprintf(PrPattern, refOrg, refRepo, Index)
|
||||
|
||||
// payload_processing:
|
||||
for _, pr := range prs.Payload {
|
||||
lines := strings.Split(pr.Body, "\n")
|
||||
|
||||
for _, line := range lines {
|
||||
if strings.TrimSpace(line) == prLine {
|
||||
return pr, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(prs.Payload) < 10 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) RequestReviews(pr *models.PullRequest, reviewers ...string) ([]*models.PullReview, error) {
|
||||
reviewOptions := models.PullReviewRequestOptions{
|
||||
Reviewers: reviewers,
|
||||
@@ -431,6 +655,14 @@ func (gitea *GiteaTransport) RequestReviews(pr *models.PullRequest, reviewers ..
|
||||
return review.GetPayload(), nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) UnrequestReview(org, repo string, id int64, reviwers ...string) error {
|
||||
_, err := gitea.client.Repository.RepoDeletePullReviewRequests(
|
||||
repository.NewRepoDeletePullReviewRequestsParams().WithOwner(org).WithRepo(repo).WithIndex(id).WithBody(&models.PullReviewRequestOptions{
|
||||
Reviewers: reviwers,
|
||||
}), gitea.transport.DefaultAuthentication)
|
||||
return err
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state models.ReviewStateType, comment string) (*models.PullReview, error) {
|
||||
c, err := gitea.client.Repository.RepoCreatePullReview(
|
||||
repository.NewRepoCreatePullReviewParams().
|
||||
@@ -459,8 +691,15 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
|
||||
transport.DefaultAuthentication,
|
||||
)
|
||||
*/
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
/* c, err := client.Issue.IssueCreateComment(
|
||||
return c.Payload, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) AddComment(pr *models.PullRequest, comment string) error {
|
||||
_, err := gitea.client.Issue.IssueCreateComment(
|
||||
issue.NewIssueCreateCommentParams().
|
||||
WithDefaults().
|
||||
WithOwner(pr.Base.Repo.Owner.UserName).
|
||||
@@ -469,13 +708,48 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
|
||||
WithBody(&models.CreateIssueCommentOption{
|
||||
Body: &comment,
|
||||
}),
|
||||
transport.DefaultAuthentication)
|
||||
*/
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Payload, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetTimeline(org, repo string, idx int64) ([]*models.TimelineComment, error) {
|
||||
page := int64(1)
|
||||
resCount := 1
|
||||
|
||||
retData := []*models.TimelineComment{}
|
||||
|
||||
for resCount > 0 {
|
||||
res, err := gitea.client.Issue.IssueGetCommentsAndTimeline(
|
||||
issue.NewIssueGetCommentsAndTimelineParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithIndex(idx).
|
||||
WithPage(&page),
|
||||
gitea.transport.DefaultAuthentication,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resCount = len(res.Payload)
|
||||
LogDebug("page:", page, "len:", resCount)
|
||||
page++
|
||||
|
||||
retData = append(retData, res.Payload...)
|
||||
}
|
||||
LogDebug("total results:", len(retData))
|
||||
|
||||
slices.SortFunc(retData, func(a, b *models.TimelineComment) int {
|
||||
return time.Time(b.Created).Compare(time.Time(a.Created))
|
||||
})
|
||||
|
||||
return retData, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path string) ([]byte, string, error) {
|
||||
@@ -499,8 +773,14 @@ func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path stri
|
||||
}
|
||||
|
||||
data := make([]byte, content.Payload.Size)
|
||||
n, err := base64.RawStdEncoding.Decode(data, []byte(content.Payload.Content))
|
||||
n, err := base64.StdEncoding.Decode(data, []byte(content.Payload.Content))
|
||||
if err != nil {
|
||||
log.Println(content.Payload.Content[239])
|
||||
log.Println(len(content.Payload.Content))
|
||||
log.Println(string(data))
|
||||
log.Println(content.Payload.Encoding)
|
||||
enc, _ := json.MarshalIndent(content.Payload, "", " ")
|
||||
log.Println(string(enc))
|
||||
return nil, "", fmt.Errorf("Error decoding file %s/%s/%s#%s : %w", org, repo, path, hash, err)
|
||||
}
|
||||
if n != int(content.Payload.Size) {
|
||||
@@ -514,12 +794,13 @@ func (gitea *GiteaTransport) GetPullRequestFileContent(pr *models.PullRequest, p
|
||||
return gitea.GetRepositoryFileContent(pr.Head.Repo.Owner.UserName, pr.Head.Repo.Name, pr.Head.Sha, path)
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetRecentPullRequests(org, repo string) ([]*models.PullRequest, error) {
|
||||
func (gitea *GiteaTransport) GetRecentPullRequests(org, repo, branch string) ([]*models.PullRequest, error) {
|
||||
prs := make([]*models.PullRequest, 0, 10)
|
||||
var page int64
|
||||
page = 1
|
||||
sort := "recentupdate"
|
||||
|
||||
endPrs:
|
||||
for {
|
||||
res, err := gitea.client.Repository.RepoListPullRequests(
|
||||
repository.NewRepoListPullRequestsParams().
|
||||
@@ -532,15 +813,21 @@ func (gitea *GiteaTransport) GetRecentPullRequests(org, repo string) ([]*models.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prs = append(prs, res.Payload...)
|
||||
n := len(res.Payload)
|
||||
if n < 10 {
|
||||
if len(res.Payload) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
// if pr is closed for more than a week, assume that we are done too
|
||||
if time.Since(time.Time(res.Payload[n-1].Updated)) > 7*24*time.Hour {
|
||||
break
|
||||
for _, pr := range res.Payload {
|
||||
if pr.Base.Name != branch {
|
||||
continue
|
||||
}
|
||||
|
||||
// if pr is closed for more than a week, assume that we are done too
|
||||
if pr.State == "closed" && time.Since(time.Time(pr.Updated)) > 7*24*time.Hour {
|
||||
break endPrs
|
||||
}
|
||||
|
||||
prs = append(prs, pr)
|
||||
}
|
||||
|
||||
page++
|
||||
@@ -552,20 +839,26 @@ func (gitea *GiteaTransport) GetRecentPullRequests(org, repo string) ([]*models.
|
||||
func (gitea *GiteaTransport) GetRecentCommits(org, repo, branch string, commitNo int64) ([]*models.Commit, error) {
|
||||
not := false
|
||||
var page int64 = 1
|
||||
commits, err := gitea.client.Repository.RepoGetAllCommits(
|
||||
repository.NewRepoGetAllCommitsParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithSha(&branch).
|
||||
WithPage(&page).
|
||||
WithStat(¬).
|
||||
WithFiles(¬).
|
||||
WithVerification(¬).
|
||||
WithLimit(&commitNo),
|
||||
gitea.transport.DefaultAuthentication,
|
||||
)
|
||||
params := repository.NewRepoGetAllCommitsParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithPage(&page).
|
||||
WithStat(¬).
|
||||
WithFiles(¬).
|
||||
WithVerification(¬).
|
||||
WithLimit(&commitNo)
|
||||
|
||||
if len(branch) > 0 {
|
||||
params = params.WithSha(&branch)
|
||||
}
|
||||
|
||||
commits, err := gitea.client.Repository.RepoGetAllCommits(params, gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *repository.RepoGetAllCommitsNotFound:
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
317
common/listen.go
317
common/listen.go
@@ -1,317 +0,0 @@
|
||||
package common
|
||||
|
||||
/*
|
||||
* This file is part of Autogits.
|
||||
*
|
||||
* Copyright © 2024 SUSE LLC
|
||||
*
|
||||
* Autogits is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* Autogits is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* Foobar. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
rabbitmq "github.com/rabbitmq/amqp091-go"
|
||||
)
|
||||
|
||||
const RequestType_CreateBrachTag = "create"
|
||||
const RequestType_DeleteBranchTag = "delete"
|
||||
const RequestType_Fork = "fork"
|
||||
const RequestType_Issue = "issues"
|
||||
const RequestType_IssueAssign = "issue_assign"
|
||||
const RequestType_IssueComment = "issue_comment"
|
||||
const RequestType_IssueLabel = "issue_label"
|
||||
const RequestType_IssueMilestone = "issue_milestone"
|
||||
const RequestType_Push = "push"
|
||||
const RequestType_Repository = "repository"
|
||||
const RequestType_Release = "release"
|
||||
const RequestType_PR = "pull_request"
|
||||
const RequestType_PRAssign = "pull_request_assign"
|
||||
const RequestType_PRLabel = "pull_request_label"
|
||||
const RequestType_PRComment = "pull_request_comment"
|
||||
const RequestType_PRMilestone = "pull_request_milestone"
|
||||
const RequestType_PRSync = "pull_request_sync"
|
||||
const RequestType_PRReviewAccepted = "pull_request_review_approved"
|
||||
const RequestType_PRReviewRejected = "pull_request_review_rejected"
|
||||
const RequestType_PRReviewRequest = "pull_request_review_request"
|
||||
const RequestType_PRReviewComment = "pull_request_review_comment"
|
||||
const RequestType_Wiki = "wiki"
|
||||
|
||||
type RequestProcessor interface {
|
||||
ProcessFunc(*Request) error
|
||||
}
|
||||
|
||||
type ListenDefinitions struct {
|
||||
RabbitURL *url.URL // amqps://user:password@host/queue
|
||||
|
||||
GitAuthor string
|
||||
Handlers map[string]RequestProcessor
|
||||
Orgs []string
|
||||
|
||||
topics []string
|
||||
topicSubChanges chan string // +topic = subscribe, -topic = unsubscribe
|
||||
}
|
||||
|
||||
type RabbitMessage rabbitmq.Delivery
|
||||
|
||||
func (l *ListenDefinitions) processTopicChanges(ch *rabbitmq.Channel, queueName string) {
|
||||
for {
|
||||
topic, ok := <-l.topicSubChanges
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(" topic change:", topic)
|
||||
switch topic[0] {
|
||||
case '+':
|
||||
if err := ch.QueueBind(queueName, topic[1:], "pubsub", false, nil); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
case '-':
|
||||
if err := ch.QueueUnbind(queueName, topic[1:], "pubsub", nil); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
default:
|
||||
log.Println("Ignoring topic change.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListenDefinitions) processRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||
queueName := l.RabbitURL.Path
|
||||
l.RabbitURL.Path = ""
|
||||
|
||||
if len(queueName) > 0 && queueName[0] == '/' {
|
||||
queueName = queueName[1:]
|
||||
}
|
||||
|
||||
connection, err := rabbitmq.DialTLS(l.RabbitURL.String(), &tls.Config{
|
||||
ServerName: l.RabbitURL.Hostname(),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot connect to %s . Err: %w", l.RabbitURL.Hostname(), err)
|
||||
}
|
||||
defer connection.Close()
|
||||
|
||||
ch, err := connection.Channel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot create a channel. Err: %w", err)
|
||||
}
|
||||
defer ch.Close()
|
||||
|
||||
if err = ch.ExchangeDeclarePassive("pubsub", "topic", true, false, false, false, nil); err != nil {
|
||||
return fmt.Errorf("Cannot find pubsub exchange? Err: %w", err)
|
||||
}
|
||||
|
||||
var q rabbitmq.Queue
|
||||
if len(queueName) == 0 {
|
||||
q, err = ch.QueueDeclare("", false, true, true, false, nil)
|
||||
} else {
|
||||
q, err = ch.QueueDeclarePassive(queueName, true, false, true, false, nil)
|
||||
if err != nil {
|
||||
log.Printf("queue not found .. trying to create it: %v\n", err)
|
||||
if ch.IsClosed() {
|
||||
ch, err = connection.Channel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Channel cannot be re-opened. Err: %w", err)
|
||||
}
|
||||
}
|
||||
q, err = ch.QueueDeclare(queueName, true, false, true, false, nil)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("can't create persistent queue ... falling back to temporaty queue: %v\n", err)
|
||||
if ch.IsClosed() {
|
||||
ch, err = connection.Channel()
|
||||
return fmt.Errorf("Channel cannot be re-opened. Err: %w", err)
|
||||
}
|
||||
q, err = ch.QueueDeclare("", false, true, true, false, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot declare queue. Err: %w", err)
|
||||
}
|
||||
// log.Printf("queue: %s:%d", q.Name, q.Consumers)
|
||||
|
||||
log.Println(" -- listening to topics:")
|
||||
l.topicSubChanges = make(chan string)
|
||||
defer close(l.topicSubChanges)
|
||||
go l.processTopicChanges(ch, q.Name)
|
||||
|
||||
for _, topic := range l.topics {
|
||||
l.topicSubChanges <- "+" + topic
|
||||
}
|
||||
|
||||
msgs, err := ch.Consume(q.Name, "", true, true, false, false, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot start consumer. Err: %w", err)
|
||||
}
|
||||
// log.Printf("queue: %s:%d", q.Name, q.Consumers)
|
||||
|
||||
for {
|
||||
msg, ok := <-msgs
|
||||
if !ok {
|
||||
return fmt.Errorf("channel/connection closed?\n")
|
||||
}
|
||||
|
||||
msgCh <- RabbitMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListenDefinitions) connectAndProcessRabbitMQ(log *log.Logger, ch chan<- RabbitMessage) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Println(r)
|
||||
log.Println("'crash' RabbitMQ worker. Recovering... reconnecting...")
|
||||
time.Sleep(5 * time.Second)
|
||||
go l.connectAndProcessRabbitMQ(log, ch)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
err := l.processRabbitMQ(ch)
|
||||
if err != nil {
|
||||
log.Printf("Error in RabbitMQ connection. %#v", err)
|
||||
log.Println("Reconnecting in 2 seconds...")
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListenDefinitions) connectToRabbitMQ(log *log.Logger) chan RabbitMessage {
|
||||
ch := make(chan RabbitMessage, 100)
|
||||
go l.connectAndProcessRabbitMQ(log, ch)
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
func ProcessEvent(f RequestProcessor, request *Request) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Println("panic caught")
|
||||
if err, ok := r.(error); !ok {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println(string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
|
||||
if err := f.ProcessFunc(request); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (l *ListenDefinitions) generateTopics() []string {
|
||||
topics := make([]string, 0, len(l.Handlers)*len(l.Orgs))
|
||||
scope := "suse"
|
||||
if l.RabbitURL.Hostname() == "rabbit.opensuse.org" {
|
||||
scope = "opensuse"
|
||||
}
|
||||
|
||||
for _, org := range l.Orgs {
|
||||
for requestType, _ := range l.Handlers {
|
||||
topics = append(topics, fmt.Sprintf("%s.src.%s.%s.#", scope, org, requestType))
|
||||
}
|
||||
}
|
||||
|
||||
slices.Sort(topics)
|
||||
return slices.Compact(topics)
|
||||
}
|
||||
|
||||
func (l *ListenDefinitions) UpdateTopics() {
|
||||
newTopics := l.generateTopics()
|
||||
|
||||
j := 0
|
||||
next_new_topic:
|
||||
for i := 0; i < len(newTopics); i++ {
|
||||
topic := newTopics[i]
|
||||
|
||||
for j < len(l.topics) {
|
||||
cmp := strings.Compare(topic, l.topics[j])
|
||||
|
||||
if cmp == 0 {
|
||||
j++
|
||||
continue next_new_topic
|
||||
}
|
||||
|
||||
if cmp < 0 {
|
||||
l.topicSubChanges <- "+" + topic
|
||||
break
|
||||
}
|
||||
|
||||
l.topicSubChanges <- "-" + l.topics[j]
|
||||
j++
|
||||
}
|
||||
|
||||
if j == len(l.topics) {
|
||||
l.topicSubChanges <- "+" + topic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListenDefinitions) ProcessRabbitMQEvents() error {
|
||||
log.Println("RabbitMQ connection:", l.RabbitURL.String())
|
||||
log.Println(len(l.Handlers), len(l.Orgs))
|
||||
|
||||
l.RabbitURL.User = url.UserPassword(rabbitUser, rabbitPassword)
|
||||
l.topics = l.generateTopics()
|
||||
ch := l.connectToRabbitMQ(log.Default())
|
||||
|
||||
for {
|
||||
msg, ok := <-ch
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Println("event:", msg.RoutingKey)
|
||||
|
||||
route := strings.Split(msg.RoutingKey, ".")
|
||||
if len(route) > 3 {
|
||||
reqType := route[3]
|
||||
org := route[2]
|
||||
|
||||
if !slices.Contains(l.Orgs, org) {
|
||||
log.Println("Got event for unhandeled org:", org)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println("org:", org, "type:", reqType)
|
||||
if handler, found := l.Handlers[reqType]; found {
|
||||
/* h, err := CreateRequestHandler()
|
||||
if err != nil {
|
||||
log.Println("Cannot create request handler", err)
|
||||
continue
|
||||
}
|
||||
*/
|
||||
req, err := ParseRequestJSON(reqType, msg.Body)
|
||||
if err != nil {
|
||||
log.Println("Error parsing request JSON:", err)
|
||||
continue
|
||||
} else {
|
||||
log.Println("processing req", req.Type)
|
||||
// h.Request = req
|
||||
ProcessEvent(handler, req)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
handlers []string
|
||||
orgs1, orgs2 []string
|
||||
|
||||
topicDelta []string
|
||||
}{
|
||||
{
|
||||
name: "no handlers, no orgs",
|
||||
},
|
||||
{
|
||||
name: "adding one org",
|
||||
handlers: []string{"foo"},
|
||||
orgs2: []string{"newOrg"},
|
||||
topicDelta: []string{"+suse"},
|
||||
},
|
||||
}
|
||||
|
||||
u, _ := url.Parse("amqps://rabbit.example.com")
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
l := ListenDefinitions{
|
||||
Orgs: test.orgs1,
|
||||
Handlers: make(map[string]RequestProcessor),
|
||||
topicSubChanges: make(chan string, len(test.topicDelta)*10),
|
||||
RabbitURL: u,
|
||||
}
|
||||
|
||||
for _, r := range test.handlers {
|
||||
l.Handlers[r] = nil
|
||||
}
|
||||
|
||||
l.UpdateTopics()
|
||||
if len(l.topicSubChanges) != len(test.topicDelta) {
|
||||
t.Fatal("topicSubChanges != topicDelta")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,64 @@ func CreateStdoutLogger(stdout, stderr io.Writer) (*log.Logger, *log.Logger) {
|
||||
|
||||
func PanicOnError(err error) {
|
||||
if err != nil {
|
||||
LogError(err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func PanicOnErrorWithMsg(err error, msg ...any) {
|
||||
if err != nil {
|
||||
LogError(msg...)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
type LogLevel int
|
||||
|
||||
const (
|
||||
LogLevelNone = 0
|
||||
LogLevelError = 2
|
||||
LogLevelInfo = 5
|
||||
LogLevelDebug = 10
|
||||
)
|
||||
|
||||
var logLevel LogLevel = LogLevelInfo
|
||||
|
||||
func SetLoggingLevel(ll LogLevel) {
|
||||
logLevel = ll
|
||||
}
|
||||
|
||||
func SetLoggingLevelFromString(ll string) error {
|
||||
switch ll {
|
||||
case "info":
|
||||
SetLoggingLevel(LogLevelInfo)
|
||||
case "debug":
|
||||
SetLoggingLevel(LogLevelDebug)
|
||||
case "error":
|
||||
SetLoggingLevel(LogLevelError)
|
||||
case "none":
|
||||
SetLoggingLevel(LogLevelNone)
|
||||
default:
|
||||
return fmt.Errorf("Unknown logging level: %s", ll)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func LogError(params ...any) {
|
||||
if logLevel >= LogLevelError {
|
||||
log.Println(append([]any{"[E]"}, params...)...)
|
||||
}
|
||||
}
|
||||
|
||||
func LogDebug(params ...any) {
|
||||
if logLevel >= LogLevelDebug {
|
||||
log.Println(append([]any{"[D]"}, params...)...)
|
||||
}
|
||||
}
|
||||
|
||||
func LogInfo(params ...any) {
|
||||
if logLevel >= LogLevelInfo {
|
||||
log.Println(append([]any{"[I]"}, params...)...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type MaintainershipData interface {
|
||||
ListProjectMaintainers() []string
|
||||
ListPackageMaintainers(pkg string) []string
|
||||
|
||||
IsApproved(pkg string, reviews []*models.PullReview) bool
|
||||
IsApproved(pkg string, reviews []*models.PullReview, submitter string) bool
|
||||
}
|
||||
|
||||
const ProjectKey = ""
|
||||
@@ -44,12 +44,13 @@ func FetchProjectMaintainershipData(gitea GiteaMaintainershipReader, org, prjGit
|
||||
dir := true
|
||||
if err != nil || data == nil {
|
||||
dir = false
|
||||
if _, notFound := err.(*repository.RepoGetRawFileNotFound); !notFound {
|
||||
if _, notFound := err.(*repository.RepoGetContentsNotFound); !notFound {
|
||||
return nil, err
|
||||
}
|
||||
LogDebug("Falling back to maintainership file")
|
||||
data, _, err = gitea.FetchMaintainershipFile(org, prjGit, branch)
|
||||
if err != nil || data == nil {
|
||||
if _, notFound := err.(*repository.RepoGetRawFileNotFound); !notFound {
|
||||
if _, notFound := err.(*repository.RepoGetContentsNotFound); !notFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -62,7 +63,7 @@ func FetchProjectMaintainershipData(gitea GiteaMaintainershipReader, org, prjGit
|
||||
if m != nil {
|
||||
m.IsDir = dir
|
||||
m.FetchPackage = func(pkg string) ([]byte, error) {
|
||||
data , _, err := gitea.FetchMaintainershipDirFile(org, prjGit, branch, pkg)
|
||||
data, _, err := gitea.FetchMaintainershipDirFile(org, prjGit, branch, pkg)
|
||||
return data, err
|
||||
}
|
||||
}
|
||||
@@ -125,27 +126,27 @@ prjMaintainer:
|
||||
return pkgMaintainers
|
||||
}
|
||||
|
||||
func (data *MaintainershipMap) IsApproved(pkg string, reviews []*models.PullReview) bool {
|
||||
reviewers, found := data.Data[pkg]
|
||||
if !found {
|
||||
if pkg != ProjectKey && data.IsDir {
|
||||
r, err := data.FetchPackage(pkg)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
reviewers = parsePkgDirData(pkg, r)
|
||||
data.Data[pkg] = reviewers
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
func (data *MaintainershipMap) IsApproved(pkg string, reviews []*models.PullReview, submitter string) bool {
|
||||
var reviewers []string
|
||||
if pkg != ProjectKey {
|
||||
reviewers = data.ListPackageMaintainers(pkg)
|
||||
} else {
|
||||
reviewers = data.ListProjectMaintainers()
|
||||
}
|
||||
|
||||
if len(reviewers) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
LogDebug("Looking for review by:", reviewers)
|
||||
if slices.Contains(reviewers, submitter) {
|
||||
LogDebug("Submitter is maintainer. Approving.")
|
||||
return true
|
||||
}
|
||||
|
||||
for _, review := range reviews {
|
||||
if !review.Stale && review.State == ReviewStateApproved && slices.Contains(reviewers, review.User.UserName) {
|
||||
LogDebug("Reviewed by", review.User.UserName)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ func (data *MaintainershipMap) WriteMaintainershipFile(writer io.StringWriter) e
|
||||
keys = slices.Delete(keys, i, len(keys))
|
||||
}
|
||||
slices.Sort(keys)
|
||||
for i, pkg := range(keys) {
|
||||
for i, pkg := range keys {
|
||||
eol := ","
|
||||
if i == len(keys)-1 {
|
||||
eol = ""
|
||||
|
||||
@@ -120,7 +120,7 @@ func TestMaintainership(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
notFoundError := repository.NewRepoGetRawFileNotFound()
|
||||
notFoundError := repository.NewRepoGetContentsNotFound()
|
||||
for _, test := range packageTests {
|
||||
runTests := func(t *testing.T, mi common.GiteaMaintainershipReader) {
|
||||
maintainers, err := common.FetchProjectMaintainershipData(mi, config.Organization, config.GitProjectName, config.Branch)
|
||||
|
||||
56
common/manifest.go
Normal file
56
common/manifest.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Manifest struct {
|
||||
Subdirectories []string
|
||||
}
|
||||
|
||||
func (m *Manifest) SubdirForPackage(pkg string) string {
|
||||
if m == nil {
|
||||
return pkg
|
||||
}
|
||||
|
||||
idx := -1
|
||||
matchLen := 0
|
||||
basePkg := path.Base(pkg)
|
||||
lowercasePkg := strings.ToLower(basePkg)
|
||||
|
||||
for i, sub := range m.Subdirectories {
|
||||
basename := strings.ToLower(path.Base(sub))
|
||||
if strings.HasPrefix(lowercasePkg, basename) && matchLen < len(basename) {
|
||||
idx = i
|
||||
matchLen = len(basename)
|
||||
}
|
||||
}
|
||||
|
||||
if idx > -1 {
|
||||
return path.Join(m.Subdirectories[idx], basePkg)
|
||||
}
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ReadManifestFile(filename string) (*Manifest, error) {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ParseManifestFile(data)
|
||||
}
|
||||
|
||||
func ParseManifestFile(data []byte) (*Manifest, error) {
|
||||
ret := &Manifest{}
|
||||
err := yaml.Unmarshal(data, ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
56
common/manifest_test.go
Normal file
56
common/manifest_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package common_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"src.opensuse.org/autogits/common"
|
||||
)
|
||||
|
||||
func TestManifestSubdirAssignments(t *testing.T) {
|
||||
tests := []struct {
|
||||
Name string
|
||||
ManifestContent string
|
||||
Packages []string
|
||||
ManifestLocations []string
|
||||
}{
|
||||
{
|
||||
Name: "empty manifest",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
||||
ManifestLocations: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
||||
},
|
||||
{
|
||||
Name: "only few subdirs manifest",
|
||||
ManifestContent: "subdirectories:\n - a\n - b",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "b/Boost", "NodeJS"},
|
||||
},
|
||||
{
|
||||
Name: "multilayer subdirs manifest",
|
||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "NodeJS"},
|
||||
},
|
||||
{
|
||||
Name: "multilayer subdirs manifest with trailing /",
|
||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo/\n - somedir/Node/",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS", "foobar/node2"},
|
||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "somedir/Node/NodeJS", "somedir/Node/node2"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
m, err := common.ParseManifestFile([]byte(test.ManifestContent))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, pkg := range test.Packages {
|
||||
expected := test.ManifestLocations[i]
|
||||
if l := m.SubdirForPackage(pkg); l != expected {
|
||||
t.Error("Expected:", expected, "but got:", l)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -25,17 +25,27 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:generate mockgen -source=obs_utils.go -destination=mock/obs_utils.go -typed
|
||||
|
||||
type BuildResultOptions struct {
|
||||
BinaryList bool
|
||||
OldState string
|
||||
LastBuild bool
|
||||
}
|
||||
|
||||
type ObsStatusFetcherWithState interface {
|
||||
BuildStatusWithState(project string, opts *BuildResultOptions, packages ...string) (*BuildResultList, error)
|
||||
}
|
||||
|
||||
type ObsClient struct {
|
||||
baseUrl *url.URL
|
||||
client *http.Client
|
||||
@@ -48,7 +58,7 @@ type ObsClient struct {
|
||||
}
|
||||
|
||||
func NewObsClient(host string) (*ObsClient, error) {
|
||||
baseUrl, err := url.Parse("https://" + host)
|
||||
baseUrl, err := url.Parse(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,18 +75,25 @@ func NewObsClient(host string) (*ObsClient, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
type ReleaseTargetMeta struct {
|
||||
Project string `xml:"project,attr"`
|
||||
Repository string `xml:"repository,attr"`
|
||||
Trigger string `xml:"trigger,attr"`
|
||||
}
|
||||
|
||||
type RepositoryPathMeta struct {
|
||||
Project string `xml:"project,attr"`
|
||||
Repository string `xml:"repository,attr"`
|
||||
}
|
||||
|
||||
type RepositoryMeta struct {
|
||||
Name string `xml:"name,attr"`
|
||||
BuildTrigger string `xml:"rebuild,attr,omitempty"`
|
||||
BlockMode string `xml:"block,attr,omitempty"`
|
||||
LinkedBuild string `xml:"linkedbuild,attr,omitempty"`
|
||||
Archs []string `xml:"arch"`
|
||||
Paths []RepositoryPathMeta `xml:"path"`
|
||||
Name string `xml:"name,attr"`
|
||||
BuildTrigger string `xml:"rebuild,attr,omitempty"`
|
||||
BlockMode string `xml:"block,attr,omitempty"`
|
||||
LinkedBuild string `xml:"linkedbuild,attr,omitempty"`
|
||||
ReleaseTargets []ReleaseTargetMeta `xml:"releasetarget"`
|
||||
Paths []RepositoryPathMeta `xml:"path"`
|
||||
Archs []string `xml:"arch"`
|
||||
}
|
||||
|
||||
type PersonRepoMeta struct {
|
||||
@@ -103,7 +120,7 @@ type ProjectMeta struct {
|
||||
XMLName xml.Name `xml:"project"`
|
||||
Name string `xml:"name,attr"`
|
||||
Title string `xml:"title"`
|
||||
Description string `xml:"description,omitempty"`
|
||||
Description string `xml:"description"`
|
||||
Url string `xml:"url,omitempty"`
|
||||
ScmSync string `xml:"scmsync"`
|
||||
Persons []PersonRepoMeta `xml:"person"`
|
||||
@@ -139,6 +156,34 @@ type GroupMeta struct {
|
||||
Persons PersonGroup `xml:"person"`
|
||||
}
|
||||
|
||||
type RequestStateMeta struct {
|
||||
XMLName xml.Name `xml:"state"`
|
||||
State string `xml:"name,attr"`
|
||||
}
|
||||
|
||||
type RequestActionTarget struct {
|
||||
XMLName xml.Name
|
||||
Project string `xml:"project,attr"`
|
||||
Package string `xml:"package,attr"`
|
||||
Revision *string `xml:"rev,attr,optional"`
|
||||
}
|
||||
|
||||
type RequestActionMeta struct {
|
||||
XMLName xml.Name `xml:"action"`
|
||||
Type string `xml:"type,attr"`
|
||||
Source *RequestActionTarget `xml:"source,optional"`
|
||||
Target *RequestActionTarget `xml:"target,optional"`
|
||||
}
|
||||
|
||||
type RequestMeta struct {
|
||||
XMLName xml.Name `xml:"request"`
|
||||
Id int `xml:"id,attr"`
|
||||
|
||||
Creator string `xml:"creator,attr"`
|
||||
Action *RequestActionMeta `xml:"action"`
|
||||
State RequestStateMeta `xml:"state"`
|
||||
}
|
||||
|
||||
func parseProjectMeta(data []byte) (*ProjectMeta, error) {
|
||||
var meta ProjectMeta
|
||||
err := xml.Unmarshal(data, &meta)
|
||||
@@ -149,8 +194,83 @@ func parseProjectMeta(data []byte) (*ProjectMeta, error) {
|
||||
return &meta, nil
|
||||
}
|
||||
|
||||
const (
|
||||
RequestStatus_Unknown = "unknown"
|
||||
RequestStatus_Accepted = "accepted"
|
||||
RequestStatus_Superseded = "superseded"
|
||||
RequestStatus_Declined = "declined"
|
||||
RequestStatus_Revoked = "revoked"
|
||||
RequestStatus_New = "new"
|
||||
RequestStatus_Review = "review"
|
||||
)
|
||||
|
||||
func (status *RequestStateMeta) IsFinal() bool {
|
||||
switch status.State {
|
||||
case RequestStatus_Declined, RequestStatus_Revoked, RequestStatus_Accepted, RequestStatus_Superseded:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func parseRequestXml(data []byte) (*RequestMeta, error) {
|
||||
ret := RequestMeta{}
|
||||
LogDebug("parsing: ", string(data))
|
||||
if err := xml.Unmarshal(data, &ret); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (c *ObsClient) CreateSubmitRequest(sourcePrj, sourcePkg, targetPrj string) (*RequestMeta, error) {
|
||||
url := c.baseUrl.JoinPath("request")
|
||||
query := url.Query()
|
||||
query.Add("cmd", "create")
|
||||
url.RawQuery = query.Encode()
|
||||
request := `<request>
|
||||
<action type="submit">
|
||||
<source project="` + sourcePrj + `" package="` + sourcePkg + `">
|
||||
</source>
|
||||
<target project="` + targetPrj + `" package="` + sourcePkg + `">
|
||||
</target>
|
||||
</action>
|
||||
</request>`
|
||||
res, err := c.ObsRequestRaw("POST", url.String(), strings.NewReader(request))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if res.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Unexpected return code: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseRequestXml(data)
|
||||
}
|
||||
|
||||
func (c *ObsClient) RequestStatus(requestID int) (*RequestMeta, error) {
|
||||
res, err := c.ObsRequest("GET", []string{"request", fmt.Sprint(requestID)}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Unexpected return code: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseRequestXml(data)
|
||||
}
|
||||
|
||||
func (c *ObsClient) GetGroupMeta(gid string) (*GroupMeta, error) {
|
||||
res, err := c.ObsRequest("GET", c.baseUrl.JoinPath("group", gid).String(), nil)
|
||||
res, err := c.ObsRequest("GET", []string{"group", gid}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -168,6 +288,7 @@ func (c *ObsClient) GetGroupMeta(gid string) (*GroupMeta, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var meta GroupMeta
|
||||
err = xml.Unmarshal(data, &meta)
|
||||
@@ -179,7 +300,7 @@ func (c *ObsClient) GetGroupMeta(gid string) (*GroupMeta, error) {
|
||||
}
|
||||
|
||||
func (c *ObsClient) GetUserMeta(uid string) (*UserMeta, error) {
|
||||
res, err := c.ObsRequest("GET", c.baseUrl.JoinPath("person", uid).String(), nil)
|
||||
res, err := c.ObsRequest("GET", []string{"person", uid}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -197,6 +318,7 @@ func (c *ObsClient) GetUserMeta(uid string) (*UserMeta, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var meta UserMeta
|
||||
err = xml.Unmarshal(data, &meta)
|
||||
@@ -207,7 +329,11 @@ func (c *ObsClient) GetUserMeta(uid string) (*UserMeta, error) {
|
||||
return &meta, nil
|
||||
}
|
||||
|
||||
func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http.Response, error) {
|
||||
func (c *ObsClient) ObsRequest(method string, url_path []string, body io.Reader) (*http.Response, error) {
|
||||
return c.ObsRequestRaw(method, c.baseUrl.JoinPath(url_path...).String(), body)
|
||||
}
|
||||
|
||||
func (c *ObsClient) ObsRequestRaw(method string, url string, body io.Reader) (*http.Response, error) {
|
||||
req, err := http.NewRequest(method, url, body)
|
||||
|
||||
if err != nil {
|
||||
@@ -220,6 +346,12 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
req.Header.Add("cookie", c.cookie)
|
||||
}
|
||||
res, err := c.client.Do(req)
|
||||
|
||||
if err != nil && res == nil {
|
||||
LogDebug("No res headers:", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if err == nil && res.StatusCode == 200 {
|
||||
auth_cookie := res.Header.Get("set-cookie")
|
||||
if auth_cookie != "" {
|
||||
@@ -229,8 +361,8 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
}
|
||||
|
||||
if res.StatusCode == 401 {
|
||||
// log.Printf("new authentication is needed ...")
|
||||
if c.sshkey == "" {
|
||||
LogDebug("setting basic auth")
|
||||
req.SetBasicAuth(c.user, c.password)
|
||||
} else {
|
||||
www := res.Header.Get("www-authenticate")
|
||||
@@ -241,25 +373,19 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
return nil, errors.New("No realm found")
|
||||
}
|
||||
realm := string(match[1])
|
||||
sshKeygenPath, err := exec.LookPath("ssh-keygen")
|
||||
if err != nil {
|
||||
fmt.Println("ssh-keygen not found")
|
||||
}
|
||||
|
||||
// SSH Sign
|
||||
cmd := exec.Command(sshKeygenPath, "-Y", "sign", "-f", c.sshkeyfile, "-n", realm, "-q")
|
||||
cmd := exec.Command("ssh-keygen", "-Y", "sign", "-f", c.sshkeyfile, "-n", realm, "-q")
|
||||
now := time.Now().Unix()
|
||||
sigdata := fmt.Sprintf("(created): %d", now)
|
||||
cmd.Stdin = strings.NewReader(sigdata)
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Panic("SSH sign error:%s", cmd.Stderr)
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
waitStatus := exitError.Sys().(syscall.WaitStatus)
|
||||
exitCode := waitStatus.ExitStatus()
|
||||
return nil, errors.New(fmt.Sprintf("ssh-keygen signature creation failed: %d", exitCode))
|
||||
exitCode := -1337
|
||||
if cmd.ProcessState != nil {
|
||||
exitCode = cmd.ProcessState.ExitCode()
|
||||
}
|
||||
return nil, errors.New("ssh-keygen signature creation failed")
|
||||
return nil, errors.New(fmt.Sprintf("ssh-keygen signature creation failed: %d", exitCode))
|
||||
}
|
||||
reg := regexp.MustCompile("(?s)-----BEGIN SSH SIGNATURE-----\n(.*?)\n-----END SSH SIGNATURE-----")
|
||||
match = reg.FindStringSubmatch(string(stdout))
|
||||
@@ -267,7 +393,7 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
return nil, errors.New("could not extract ssh signature")
|
||||
}
|
||||
|
||||
signature, err := base64.StdEncoding.DecodeString(string(match[1]))
|
||||
signature, err := base64.StdEncoding.DecodeString(match[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -276,31 +402,35 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
authorization := fmt.Sprintf(`keyId="%s",algorithm="ssh",headers="(created)",created=%d,signature="%s"`,
|
||||
c.user, now, signatureBase64)
|
||||
|
||||
// log.Printf("Add Authorization Signature ", authorization)
|
||||
// log.Printf("Add Authorization Signature ", authorization)
|
||||
req.Header.Add("Authorization", "Signature "+authorization)
|
||||
}
|
||||
|
||||
// Another time with authentification header
|
||||
LogDebug("Trying again with authorization for", req.URL.String())
|
||||
res, err = c.client.Do(req)
|
||||
if err != nil {
|
||||
if res != nil {
|
||||
LogError("Authentification failed:", res.StatusCode)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Another time with authentification header
|
||||
// log.Printf("Trying again with authorization: %s", req.Header.Get("Authorization"))
|
||||
|
||||
res, err = c.client.Do(req)
|
||||
if err != nil {
|
||||
log.Panic("Authentification failed: %d", res.StatusCode)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Store the cookie for next call
|
||||
auth_cookie := res.Header.Get("set-cookie")
|
||||
if auth_cookie != "" {
|
||||
c.cookie = auth_cookie
|
||||
if err == nil {
|
||||
// Store the cookie for next call
|
||||
auth_cookie := res.Header.Get("set-cookie")
|
||||
if auth_cookie != "" {
|
||||
c.cookie = auth_cookie
|
||||
}
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (c *ObsClient) GetProjectMeta(project string) (*ProjectMeta, error) {
|
||||
res, err := c.ObsRequest("GET", c.baseUrl.JoinPath("source", project, "_meta").String(), nil)
|
||||
req := []string{"source", project, "_meta"}
|
||||
res, err := c.ObsRequest("GET", req, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -312,7 +442,7 @@ func (c *ObsClient) GetProjectMeta(project string) (*ProjectMeta, error) {
|
||||
case 404:
|
||||
return nil, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Unexpected return code: %d", res.StatusCode)
|
||||
return nil, fmt.Errorf("Unexpected return code: %d %s %w", res.StatusCode, req, err)
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(res.Body)
|
||||
@@ -320,11 +450,12 @@ func (c *ObsClient) GetProjectMeta(project string) (*ProjectMeta, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
return parseProjectMeta(data)
|
||||
}
|
||||
|
||||
func (c *ObsClient) GetPackageMeta(project, pkg string) (*PackageMeta, error) {
|
||||
res, err := c.ObsRequest("GET", c.baseUrl.JoinPath("source", project, pkg, "_meta").String(), nil)
|
||||
res, err := c.ObsRequest("GET", []string{"source", project, pkg, "_meta"}, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -343,6 +474,7 @@ func (c *ObsClient) GetPackageMeta(project, pkg string) (*PackageMeta, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var meta PackageMeta
|
||||
err = xml.Unmarshal(data, &meta)
|
||||
@@ -397,10 +529,11 @@ func (c *ObsClient) SetProjectMeta(meta *ProjectMeta) error {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := c.ObsRequest("PUT", c.baseUrl.JoinPath("source", meta.Name, "_meta").String(), io.NopCloser(bytes.NewReader(xml)))
|
||||
res, err := c.ObsRequest("PUT", []string{"source", meta.Name, "_meta"}, io.NopCloser(bytes.NewReader(xml)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
switch res.StatusCode {
|
||||
case 200:
|
||||
@@ -413,17 +546,37 @@ func (c *ObsClient) SetProjectMeta(meta *ProjectMeta) error {
|
||||
}
|
||||
|
||||
func (c *ObsClient) DeleteProject(project string) error {
|
||||
res, err := c.ObsRequest("DELETE", c.baseUrl.JoinPath("source", project).String(), nil)
|
||||
url := c.baseUrl.JoinPath("source", project)
|
||||
query := url.Query()
|
||||
query.Add("force", "1")
|
||||
url.RawQuery = query.Encode()
|
||||
res, err := c.ObsRequestRaw("DELETE", url.String(), nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return fmt.Errorf("Unexpected return code: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ObsClient) BuildLog(prj, pkg, repo, arch string) (io.ReadCloser, error) {
|
||||
url := c.baseUrl.JoinPath("build", prj, repo, arch, pkg, "_log")
|
||||
query := url.Query()
|
||||
query.Add("nostream", "1")
|
||||
query.Add("start", "0")
|
||||
url.RawQuery = query.Encode()
|
||||
res, err := c.ObsRequestRaw("GET", url.String(), nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Body, nil
|
||||
}
|
||||
|
||||
type PackageBuildStatus struct {
|
||||
@@ -438,6 +591,8 @@ type BuildResult struct {
|
||||
Arch string `xml:"arch,attr"`
|
||||
Code string `xml:"code,attr"`
|
||||
Dirty bool `xml:"dirty,attr"`
|
||||
ScmSync string `xml:"scmsync"`
|
||||
ScmInfo string `xml:"scminfo"`
|
||||
Status []PackageBuildStatus `xml:"status"`
|
||||
Binaries []BinaryList `xml:"binarylist"`
|
||||
}
|
||||
@@ -455,20 +610,27 @@ type BinaryList struct {
|
||||
|
||||
type BuildResultList struct {
|
||||
XMLName xml.Name `xml:"resultlist"`
|
||||
State string `xml:"state,attr"`
|
||||
Result []BuildResult `xml:"result"`
|
||||
|
||||
isLastBuild bool
|
||||
}
|
||||
|
||||
func (r *BuildResultList) GetPackageList() []string {
|
||||
pkgList := make([]string, 0, 16)
|
||||
|
||||
for _, res := range r.Result {
|
||||
// TODO: enough to iterate over one result set?
|
||||
pkgList := make([]string, 0, 3*len(r.Result[0].Status)/2)
|
||||
|
||||
for ridx, res := range r.Result {
|
||||
for _, status := range res.Status {
|
||||
if !slices.Contains(pkgList, status.Package) {
|
||||
if ridx == 0 {
|
||||
pkgList = append(pkgList, status.Package)
|
||||
} else if idx, found := slices.BinarySearch(pkgList, status.Package); !found {
|
||||
pkgList = slices.Insert(pkgList, idx, status.Package)
|
||||
}
|
||||
}
|
||||
|
||||
if ridx == 0 {
|
||||
slices.Sort(pkgList)
|
||||
}
|
||||
}
|
||||
|
||||
return pkgList
|
||||
@@ -476,7 +638,7 @@ func (r *BuildResultList) GetPackageList() []string {
|
||||
|
||||
func (r *BuildResultList) BuildResultSummary() (success, finished bool) {
|
||||
if r == nil {
|
||||
return true, true
|
||||
return false, false
|
||||
}
|
||||
|
||||
finished = len(r.Result) > 0 && len(r.Result[0].Status) > 0
|
||||
@@ -489,7 +651,7 @@ func (r *BuildResultList) BuildResultSummary() (success, finished bool) {
|
||||
panic("Unknown repo result code: " + resultSet.Code)
|
||||
}
|
||||
|
||||
finished = repoDetail.Finished
|
||||
finished = r.isLastBuild || repoDetail.Finished
|
||||
if !finished || resultSet.Dirty {
|
||||
return
|
||||
}
|
||||
@@ -500,6 +662,11 @@ func (r *BuildResultList) BuildResultSummary() (success, finished bool) {
|
||||
if !ok {
|
||||
panic("Unknown result code: " + result.Code)
|
||||
}
|
||||
if r.isLastBuild && result.Code == "unknown" {
|
||||
// it means the package has never build yet,
|
||||
// but we don't know the reason
|
||||
detail.Finished = true
|
||||
}
|
||||
|
||||
finished = finished && detail.Finished
|
||||
success = success && detail.Success
|
||||
@@ -595,9 +762,14 @@ var ObsBuildStatusDetails map[string]ObsBuildStatusDetail = map[string]ObsBuildS
|
||||
},
|
||||
"unknown": ObsBuildStatusDetail{
|
||||
Code: "unknown",
|
||||
Description: "The scheduler has not yet evaluated this package. Should be a short intermediate state for new packages.",
|
||||
Description: "The scheduler has not yet evaluated this package. Should be a short intermediate state for new packages. When used for lastbuild state it means it was never possible to attempt a build",
|
||||
Finished: false,
|
||||
},
|
||||
|
||||
"error": ObsBuildStatusDetail{
|
||||
Code: "Error",
|
||||
Description: "Unknown status code",
|
||||
},
|
||||
}
|
||||
var ObsRepoStatusDetails map[string]ObsBuildStatusDetail = map[string]ObsBuildStatusDetail{
|
||||
// repo status
|
||||
@@ -641,6 +813,11 @@ var ObsRepoStatusDetails map[string]ObsBuildStatusDetail = map[string]ObsBuildSt
|
||||
Description: "The repository state is being calculated right now",
|
||||
Finished: false,
|
||||
},
|
||||
"unknown": ObsBuildStatusDetail{
|
||||
Code: "unknown",
|
||||
Description: "The repository state has not been seen by the scheduler yet",
|
||||
Finished: false,
|
||||
},
|
||||
}
|
||||
|
||||
func parseBuildResults(data []byte) (*BuildResultList, error) {
|
||||
@@ -662,14 +839,13 @@ func (obs ObsProjectNotFound) Error() string {
|
||||
}
|
||||
|
||||
func (c *ObsClient) ProjectConfig(project string) (string, error) {
|
||||
u := c.baseUrl.JoinPath("source", project, "_config")
|
||||
|
||||
res, err := c.ObsRequest("GET", u.String(), nil)
|
||||
res, err := c.ObsRequest("GET", []string{"source", project, "_config"}, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if data, err := io.ReadAll(res.Body); err == nil {
|
||||
defer res.Body.Close()
|
||||
return string(data), nil
|
||||
} else {
|
||||
return "", err
|
||||
@@ -677,19 +853,34 @@ func (c *ObsClient) ProjectConfig(project string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *ObsClient) BuildStatus(project string, packages ...string) (*BuildResultList, error) {
|
||||
return c.BuildStatusWithState(project, &BuildResultOptions{}, packages...)
|
||||
}
|
||||
|
||||
func (c *ObsClient) LastBuildResults(project string, packages ...string) (*BuildResultList, error) {
|
||||
return c.BuildStatusWithState(project, &BuildResultOptions{LastBuild: true}, packages...)
|
||||
}
|
||||
|
||||
func (c *ObsClient) BuildStatusWithState(project string, opts *BuildResultOptions, packages ...string) (*BuildResultList, error) {
|
||||
u := c.baseUrl.JoinPath("build", project, "_result")
|
||||
query := u.Query()
|
||||
query.Add("view", "status")
|
||||
query.Add("view", "binarylist")
|
||||
if opts.BinaryList {
|
||||
query.Add("view", "binarylist")
|
||||
}
|
||||
query.Add("multibuild", "1")
|
||||
if len(packages) > 0 {
|
||||
if len(opts.OldState) > 0 {
|
||||
query.Add("oldstate", opts.OldState)
|
||||
}
|
||||
if opts.LastBuild {
|
||||
query.Add("lastbuild", "1")
|
||||
}
|
||||
if len(packages) > 0 {
|
||||
for _, pkg := range packages {
|
||||
query.Add("package", pkg)
|
||||
}
|
||||
}
|
||||
u.RawQuery = query.Encode()
|
||||
res, err := c.ObsRequest("GET", u.String(), nil)
|
||||
res, err := c.ObsRequestRaw("GET", u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -707,5 +898,10 @@ func (c *ObsClient) BuildStatus(project string, packages ...string) (*BuildResul
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseBuildResults(data)
|
||||
defer res.Body.Close()
|
||||
ret, err := parseBuildResults(data)
|
||||
if ret != nil {
|
||||
ret.isLastBuild = opts.LastBuild
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
@@ -55,6 +55,52 @@ func TestParsingOfBuildResults(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsingRequestResults(t *testing.T) {
|
||||
res, err := parseRequestXml([]byte(metaRequestData))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res.Id != 42 ||
|
||||
res.Action.Source.Project != "home:foo-user" ||
|
||||
res.Action.Source.Package != "obs-server" ||
|
||||
*res.Action.Source.Revision != "521e" ||
|
||||
res.Action.Target.Project != "OBS:Unstable" ||
|
||||
res.Action.Target.Revision != nil {
|
||||
|
||||
t.Fatal(res)
|
||||
}
|
||||
}
|
||||
|
||||
const metaRequestData = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<request id="42" creator="foo-user">
|
||||
<action type="submit">
|
||||
<source project="home:foo-user" package="obs-server" rev="521e">
|
||||
</source>
|
||||
<target project="OBS:Unstable" package="obs-server">
|
||||
</target>
|
||||
<options>
|
||||
<sourceupdate>cleanup</sourceupdate>
|
||||
</options>
|
||||
</action>
|
||||
<state name="accepted" who="bar-user" when="2021-01-15T13:39:43">
|
||||
<comment>allright</comment>
|
||||
</state>
|
||||
<review state="accepted" when="2021-01-15T15:49:32" who="obs-maintainer" by_user="obs-maintainer">
|
||||
</review>
|
||||
<review state="accepted" when="2021-01-15T15:49:32" who="obs-maintainer" by_group="obs-group">
|
||||
</review>
|
||||
<review state="accepted" when="2021-01-15T15:49:32" who="obs-maintainer" by_project="OBS:Unstable">
|
||||
</review>
|
||||
<review state="accepted" when="2021-01-15T15:49:32" who="obs-maintainer" by_package="obs-server">
|
||||
</review>
|
||||
<history who="foo" when="2021-01-15T13:39:43">
|
||||
<description>Request created</description>
|
||||
<comment>Please review sources</comment>
|
||||
</history>
|
||||
<description>A little version update</description>
|
||||
</request>`
|
||||
|
||||
const metaPrjData = `
|
||||
<project name="home:adamm">
|
||||
<title>Adam's Home Projects</title>
|
||||
|
||||
304
common/pr.go
304
common/pr.go
@@ -13,25 +13,36 @@ import (
|
||||
)
|
||||
|
||||
type PRInfo struct {
|
||||
PR *models.PullRequest
|
||||
Reviews *PRReviews
|
||||
PR *models.PullRequest
|
||||
Reviews *PRReviews
|
||||
RemoteName string
|
||||
}
|
||||
|
||||
type PRSet struct {
|
||||
PRs []PRInfo
|
||||
PRs []*PRInfo
|
||||
Config *AutogitConfig
|
||||
|
||||
BotUser string
|
||||
}
|
||||
|
||||
func readPRData(gitea GiteaPRFetcher, pr *models.PullRequest, currentSet []PRInfo, config *AutogitConfig) ([]PRInfo, error) {
|
||||
func (prinfo *PRInfo) PRComponents() (org string, repo string, idx int64) {
|
||||
org = prinfo.PR.Base.Repo.Owner.UserName
|
||||
repo = prinfo.PR.Base.Repo.Name
|
||||
idx = prinfo.PR.Index
|
||||
return
|
||||
}
|
||||
|
||||
func readPRData(gitea GiteaPRFetcher, pr *models.PullRequest, currentSet []*PRInfo, config *AutogitConfig) ([]*PRInfo, error) {
|
||||
for _, p := range currentSet {
|
||||
if pr.Index == p.PR.Index && pr.Base.Repo.Name == p.PR.Base.Repo.Name && pr.Base.Repo.Owner.UserName == p.PR.Base.Repo.Owner.UserName {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
retSet := []PRInfo{PRInfo{PR: pr}}
|
||||
retSet := []*PRInfo{&PRInfo{PR: pr}}
|
||||
|
||||
// only need to extact there on PrjGit PR
|
||||
if pr.Base.Repo.Name == config.GitProjectName && pr.Base.Repo.Owner.UserName == config.Organization {
|
||||
org, repo, _ := config.GetPrjGit()
|
||||
if pr.Base.Repo.Name == repo && pr.Base.Repo.Owner.UserName == org {
|
||||
_, refPRs := ExtractDescriptionAndPRs(bufio.NewScanner(strings.NewReader(pr.Body)))
|
||||
for _, prdata := range refPRs {
|
||||
pr, err := gitea.GetPullRequest(prdata.Org, prdata.Repo, prdata.Num)
|
||||
@@ -49,12 +60,52 @@ func readPRData(gitea GiteaPRFetcher, pr *models.PullRequest, currentSet []PRInf
|
||||
return retSet, nil
|
||||
}
|
||||
|
||||
func FetchPRSet(gitea GiteaPRFetcher, org, repo string, num int64, config *AutogitConfig) (*PRSet, error) {
|
||||
var Timeline_RefIssueNotFound error = errors.New("RefIssue not found on the timeline")
|
||||
|
||||
func LastPrjGitRefOnTimeline(gitea GiteaPRTimelineFetcher, org, repo string, num int64, prjGitOrg, prjGitRepo string) (*models.PullRequest, error) {
|
||||
prRefLine := fmt.Sprintf(PrPattern, org, repo, num)
|
||||
timeline, err := gitea.GetTimeline(org, repo, num)
|
||||
if err != nil {
|
||||
LogError("Failed to fetch timeline for", org, repo, "#", num, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for idx := len(timeline) - 1; idx >= 0; idx-- {
|
||||
item := timeline[idx]
|
||||
issue := item.RefIssue
|
||||
if item.Type == TimelineCommentType_PullRequestRef &&
|
||||
issue != nil &&
|
||||
issue.Repository != nil &&
|
||||
issue.Repository.Owner == prjGitOrg &&
|
||||
issue.Repository.Name == prjGitRepo {
|
||||
|
||||
lines := SplitLines(item.RefIssue.Body)
|
||||
for _, line := range lines {
|
||||
if strings.TrimSpace(line) == prRefLine {
|
||||
LogDebug("Found PrjGit PR in Timeline:", issue.Index)
|
||||
|
||||
// found prjgit PR in timeline. Return it
|
||||
return gitea.GetPullRequest(prjGitOrg, prjGitRepo, issue.Index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug("PrjGit RefIssue not found on timeline in", org, repo, num)
|
||||
return nil, Timeline_RefIssueNotFound
|
||||
}
|
||||
|
||||
func FetchPRSet(user string, gitea GiteaPRTimelineFetcher, org, repo string, num int64, config *AutogitConfig) (*PRSet, error) {
|
||||
var pr *models.PullRequest
|
||||
var err error
|
||||
|
||||
if org != config.Organization || repo != config.GitProjectName {
|
||||
if pr, err = gitea.GetAssociatedPrjGitPR(config.Organization, config.GitProjectName, org, repo, num); err != nil {
|
||||
prjGitOrg, prjGitRepo, _ := config.GetPrjGit()
|
||||
if prjGitOrg == org && prjGitRepo == repo {
|
||||
if pr, err = gitea.GetPullRequest(org, repo, num); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if pr, err = LastPrjGitRefOnTimeline(gitea, org, repo, num, prjGitOrg, prjGitRepo); err != nil && err != Timeline_RefIssueNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -63,10 +114,6 @@ func FetchPRSet(gitea GiteaPRFetcher, org, repo string, num int64, config *Autog
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if pr, err = gitea.GetPullRequest(org, repo, num); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
prs, err := readPRData(gitea, pr, nil, config)
|
||||
@@ -74,22 +121,54 @@ func FetchPRSet(gitea GiteaPRFetcher, org, repo string, num int64, config *Autog
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &PRSet{PRs: prs, Config: config}, nil
|
||||
return &PRSet{
|
||||
PRs: prs,
|
||||
Config: config,
|
||||
BotUser: user,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (rs *PRSet) Find(pr *models.PullRequest) (*PRInfo, bool) {
|
||||
for _, p := range rs.PRs {
|
||||
if p.PR.Base.RepoID == pr.Base.RepoID &&
|
||||
p.PR.Head.Sha == pr.Head.Sha &&
|
||||
p.PR.Base.Name == pr.Base.Name {
|
||||
return p, true
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (rs *PRSet) AddPR(pr *models.PullRequest) *PRInfo {
|
||||
if pr, found := rs.Find(pr); found {
|
||||
return pr
|
||||
}
|
||||
|
||||
prinfo := &PRInfo{
|
||||
PR: pr,
|
||||
}
|
||||
rs.PRs = append(rs.PRs, prinfo)
|
||||
return prinfo
|
||||
}
|
||||
|
||||
func (rs *PRSet) IsPrjGitPR(pr *models.PullRequest) bool {
|
||||
return pr.Base.Repo.Name == rs.Config.GitProjectName && pr.Base.Repo.Owner.UserName == rs.Config.Organization
|
||||
org, repo, branch := rs.Config.GetPrjGit()
|
||||
return pr.Base.Name == branch && pr.Base.Repo.Name == repo && pr.Base.Repo.Owner.UserName == org
|
||||
}
|
||||
|
||||
func (rs *PRSet) GetPrjGitPR() (*models.PullRequest, error) {
|
||||
var ret *models.PullRequest
|
||||
var PRSet_PrjGitMissing error = errors.New("No PrjGit PR found")
|
||||
var PRSet_MultiplePrjGit error = errors.New("Multiple PrjGit PRs in one review set")
|
||||
|
||||
func (rs *PRSet) GetPrjGitPR() (*PRInfo, error) {
|
||||
var ret *PRInfo
|
||||
|
||||
for _, prinfo := range rs.PRs {
|
||||
if rs.IsPrjGitPR(prinfo.PR) {
|
||||
if ret == nil {
|
||||
ret = prinfo.PR
|
||||
ret = prinfo
|
||||
} else {
|
||||
return nil, errors.New("Multiple PrjGit PRs in one review set")
|
||||
return nil, PRSet_MultiplePrjGit
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,21 +177,37 @@ func (rs *PRSet) GetPrjGitPR() (*models.PullRequest, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("No PrjGit PR found")
|
||||
return nil, PRSet_PrjGitMissing
|
||||
}
|
||||
|
||||
func (rs *PRSet) NeedRecreatingPrjGit(currentBranchHash string) bool {
|
||||
pr, err := rs.GetPrjGitPR()
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return pr.PR.Base.Sha == currentBranchHash
|
||||
}
|
||||
|
||||
func (rs *PRSet) IsConsistent() bool {
|
||||
prjpr, err := rs.GetPrjGitPR()
|
||||
prjpr_info, err := rs.GetPrjGitPR()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
prjpr := prjpr_info.PR
|
||||
|
||||
_, prjpr_set := ExtractDescriptionAndPRs(bufio.NewScanner(strings.NewReader(prjpr.Body)))
|
||||
if len(prjpr_set) != len(rs.PRs)-1 { // 1 to many mapping
|
||||
LogDebug("Number of PR from links:", len(prjpr_set), "is not what's expected", len(rs.PRs)-1)
|
||||
return false
|
||||
}
|
||||
|
||||
next_rs:
|
||||
for _, prinfo := range rs.PRs {
|
||||
if prinfo.PR.State != "open" {
|
||||
return false
|
||||
}
|
||||
|
||||
if prjpr == prinfo.PR {
|
||||
continue
|
||||
}
|
||||
@@ -132,24 +227,33 @@ func (rs *PRSet) AssignReviewers(gitea GiteaReviewFetcherAndRequester, maintaine
|
||||
|
||||
for _, pr := range rs.PRs {
|
||||
reviewers := []string{}
|
||||
|
||||
if rs.IsPrjGitPR(pr.PR) {
|
||||
reviewers = configReviewers.Prj
|
||||
reviewers = slices.Concat(configReviewers.Prj, configReviewers.PrjOptional)
|
||||
LogDebug("PrjGit submitter:", pr.PR.User.UserName)
|
||||
if len(rs.PRs) == 1 {
|
||||
reviewers = slices.Concat(reviewers, maintainers.ListProjectMaintainers())
|
||||
}
|
||||
} else {
|
||||
pkg := pr.PR.Base.Repo.Name
|
||||
reviewers = slices.Concat(configReviewers.Pkg, maintainers.ListProjectMaintainers(), maintainers.ListPackageMaintainers(pkg))
|
||||
reviewers = slices.Concat(configReviewers.Pkg, maintainers.ListProjectMaintainers(), maintainers.ListPackageMaintainers(pkg), configReviewers.PkgOptional)
|
||||
}
|
||||
|
||||
slices.Sort(reviewers)
|
||||
reviewers = slices.Compact(reviewers)
|
||||
|
||||
// submitters do not need to review their own work
|
||||
if idx := slices.Index(reviewers, pr.PR.User.UserName); idx != -1 {
|
||||
reviewers = slices.Delete(reviewers, idx, idx+1)
|
||||
}
|
||||
|
||||
LogDebug("PR: ", pr.PR.Base.Repo.Name, pr.PR.Index)
|
||||
LogDebug("reviewers for PR:", reviewers)
|
||||
|
||||
// remove reviewers that were already requested and are not stale
|
||||
reviews, err := FetchGiteaReviews(gitea, reviewers, pr.PR.Base.Repo.Owner.UserName, pr.PR.Base.Repo.Name, pr.PR.Index)
|
||||
if err != nil {
|
||||
LogError("Error fetching reviews:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -157,6 +261,7 @@ func (rs *PRSet) AssignReviewers(gitea GiteaReviewFetcherAndRequester, maintaine
|
||||
user := reviewers[idx]
|
||||
if reviews.HasPendingReviewBy(user) || reviews.IsReviewedBy(user) {
|
||||
reviewers = slices.Delete(reviewers, idx, idx+1)
|
||||
LogDebug("removing reviewer:", user)
|
||||
} else {
|
||||
idx++
|
||||
}
|
||||
@@ -164,8 +269,13 @@ func (rs *PRSet) AssignReviewers(gitea GiteaReviewFetcherAndRequester, maintaine
|
||||
|
||||
// get maintainers associated with the PR too
|
||||
if len(reviewers) > 0 {
|
||||
if _, err := gitea.RequestReviews(pr.PR, reviewers...); err != nil {
|
||||
return fmt.Errorf("Cannot create reviews on %s/%s#%d for [%s]: %w", pr.PR.Base.Repo.Owner.UserName, pr.PR.Base.Repo.Name, pr.PR.Index, strings.Join(reviewers, ", "), err)
|
||||
LogDebug("Requesting reviews from:", reviewers)
|
||||
if !IsDryRun {
|
||||
for _, r := range reviewers {
|
||||
if _, err := gitea.RequestReviews(pr.PR, r); err != nil {
|
||||
LogError("Cannot create reviews on", fmt.Sprintf("%s/%s#%d for [%s]", pr.PR.Base.Repo.Owner.UserName, pr.PR.Base.Repo.Name, pr.PR.Index, strings.Join(reviewers, ", ")), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,7 +285,54 @@ func (rs *PRSet) AssignReviewers(gitea GiteaReviewFetcherAndRequester, maintaine
|
||||
func (rs *PRSet) IsApproved(gitea GiteaPRChecker, maintainers MaintainershipData) bool {
|
||||
configReviewers := ParseReviewers(rs.Config.Reviewers)
|
||||
|
||||
is_reviewed := false
|
||||
is_manually_reviewed_ok := false
|
||||
|
||||
if need_manual_review := rs.Config.ManualMergeOnly || rs.Config.ManualMergeProject; need_manual_review {
|
||||
prjgit, err := rs.GetPrjGitPR()
|
||||
if err == nil && prjgit != nil {
|
||||
reviewers := slices.Concat(configReviewers.Prj, maintainers.ListProjectMaintainers())
|
||||
LogDebug("Fetching reviews for", prjgit.PR.Base.Repo.Owner.UserName, prjgit.PR.Base.Repo.Name, prjgit.PR.Index)
|
||||
r, err := FetchGiteaReviews(gitea, reviewers, prjgit.PR.Base.Repo.Owner.UserName, prjgit.PR.Base.Repo.Name, prjgit.PR.Index)
|
||||
if err != nil {
|
||||
LogError("Cannot fetch gita reaviews for PR:", err)
|
||||
return false
|
||||
}
|
||||
prjgit.Reviews = r
|
||||
if prjgit.Reviews.IsManualMergeOK() {
|
||||
is_manually_reviewed_ok = true
|
||||
}
|
||||
}
|
||||
|
||||
if !is_manually_reviewed_ok && !rs.Config.ManualMergeProject {
|
||||
for _, pr := range rs.PRs {
|
||||
if rs.IsPrjGitPR(pr.PR) {
|
||||
continue
|
||||
}
|
||||
|
||||
pkg := pr.PR.Base.Repo.Name
|
||||
reviewers := slices.Concat(configReviewers.Pkg, maintainers.ListPackageMaintainers(pkg))
|
||||
LogDebug("Fetching reviews for", pr.PR.Base.Repo.Owner.UserName, pr.PR.Base.Repo.Name, pr.PR.Index)
|
||||
r, err := FetchGiteaReviews(gitea, reviewers, pr.PR.Base.Repo.Owner.UserName, pr.PR.Base.Repo.Name, pr.PR.Index)
|
||||
if err != nil {
|
||||
LogError("Cannot fetch gita reaviews for PR:", err)
|
||||
return false
|
||||
}
|
||||
pr.Reviews = r
|
||||
if !pr.Reviews.IsManualMergeOK() {
|
||||
LogInfo("Not approved manual merge. PR:", pr.PR.URL)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
is_manually_reviewed_ok = true
|
||||
}
|
||||
|
||||
if !is_manually_reviewed_ok {
|
||||
LogInfo("manual merge not ok")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for _, pr := range rs.PRs {
|
||||
var reviewers []string
|
||||
var pkg string
|
||||
@@ -187,48 +344,60 @@ func (rs *PRSet) IsApproved(gitea GiteaPRChecker, maintainers MaintainershipData
|
||||
pkg = pr.PR.Base.Repo.Name
|
||||
}
|
||||
|
||||
if strings.HasPrefix(pr.PR.Title, "WIP:") {
|
||||
LogInfo("WIP PR. Ignoring")
|
||||
return false
|
||||
}
|
||||
|
||||
r, err := FetchGiteaReviews(gitea, reviewers, pr.PR.Base.Repo.Owner.UserName, pr.PR.Base.Repo.Name, pr.PR.Index)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
is_reviewed = r.IsApproved()
|
||||
if !is_reviewed {
|
||||
LogError("Cannot fetch gita reaviews for PR:", err)
|
||||
return false
|
||||
}
|
||||
|
||||
if is_reviewed = maintainers.IsApproved(pkg, r.reviews); !is_reviewed {
|
||||
is_manually_reviewed_ok = r.IsApproved()
|
||||
LogDebug(pr.PR.Base.Repo.Name, is_manually_reviewed_ok)
|
||||
if !is_manually_reviewed_ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if need_maintainer_review := !rs.IsPrjGitPR(pr.PR) || pr.PR.User.UserName != rs.BotUser; need_maintainer_review {
|
||||
if is_manually_reviewed_ok = maintainers.IsApproved(pkg, r.reviews, pr.PR.User.UserName); !is_manually_reviewed_ok {
|
||||
LogDebug(" not approved?", pkg)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
LogDebug("PrjGit PR -- bot created, no need for review")
|
||||
}
|
||||
}
|
||||
return is_reviewed
|
||||
return is_manually_reviewed_ok
|
||||
}
|
||||
|
||||
func (rs *PRSet) Merge(author, email string) error {
|
||||
prjgit, err := rs.GetPrjGitPR()
|
||||
func (rs *PRSet) Merge(gitea GiteaReviewUnrequester, git Git) error {
|
||||
prjgit_info, err := rs.GetPrjGitPR()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prjgit := prjgit_info.PR
|
||||
|
||||
gh := GitHandlerGeneratorImpl{}
|
||||
git, err := gh.CreateGitHandler(author, email, prjgit.Base.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
git.GitExecOrPanic("", "clone", "--depth", "1", prjgit.Base.Repo.SSHURL, DefaultGitPrj)
|
||||
git.GitExecOrPanic(DefaultGitPrj, "fetch", "origin", prjgit.Base.Sha, prjgit.Head.Sha)
|
||||
remote, err := git.GitClone(DefaultGitPrj, rs.Config.Branch, prjgit.Base.Repo.SSHURL)
|
||||
PanicOnError(err)
|
||||
git.GitExecOrPanic(DefaultGitPrj, "fetch", remote, prjgit.Head.Sha)
|
||||
|
||||
// if other changes merged, check if we have conflicts
|
||||
rev := strings.TrimSpace(git.GitExecWithOutputOrPanic(DefaultGitPrj, "merge-base", "HEAD", prjgit.Base.Sha, prjgit.Head.Sha))
|
||||
if rev != prjgit.Base.Sha {
|
||||
return fmt.Errorf("Base.Sha (%s) not yet merged into project-git. Aborting merge.", prjgit.Base.Sha)
|
||||
}
|
||||
/*
|
||||
rev := strings.TrimSpace(git.GitExecWithOutputOrPanic(DefaultGitPrj, "merge-base", "HEAD", prjgit.Base.Sha, prjgit.Head.Sha))
|
||||
if rev != prjgit.Base.Sha {
|
||||
return fmt.Errorf("Base.Sha (%s) not yet merged into project-git. Aborting merge.", prjgit.Base.Sha)
|
||||
}
|
||||
*/
|
||||
/*
|
||||
rev := git.GitExecWithOutputOrPanic(common.DefaultGitPrj, "rev-list", "-1", "HEAD")
|
||||
if rev != prjgit.Base.Sha {
|
||||
panic("FIXME")
|
||||
}
|
||||
*/
|
||||
msg := "merging"
|
||||
msg := fmt.Sprintf("Merging\n\nPR: %s/%s#%d", prjgit.Base.Repo.Owner.UserName, prjgit.Base.Repo.Name, prjgit.Index)
|
||||
|
||||
err = git.GitExec(DefaultGitPrj, "merge", "--no-ff", "-m", msg, prjgit.Head.Sha)
|
||||
if err != nil {
|
||||
@@ -302,31 +471,58 @@ func (rs *PRSet) Merge(author, email string) error {
|
||||
return fmt.Errorf("Can't close .gitmodules: %w", err)
|
||||
}
|
||||
|
||||
os.CopyFS("/tmp/test", os.DirFS(git.GetPath()))
|
||||
|
||||
git.GitExecOrPanic(DefaultGitPrj, "add", ".gitmodules")
|
||||
git.GitExecOrPanic(DefaultGitPrj, "-c", "core.editor=true", "merge", "--continue")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FF all non-prj git
|
||||
// FF all non-prj git and unrequest reviews.
|
||||
for _, prinfo := range rs.PRs {
|
||||
// remove pending review requests
|
||||
repo := prinfo.PR.Base.Repo
|
||||
head := prinfo.PR.Head
|
||||
id := prinfo.PR.Index
|
||||
|
||||
reviewers := make([]string, len(prinfo.PR.RequestedReviewers))
|
||||
for idx := range prinfo.PR.RequestedReviewers {
|
||||
r := prinfo.PR.RequestedReviewers[idx]
|
||||
if r != nil {
|
||||
reviewers[idx] = r.UserName
|
||||
}
|
||||
}
|
||||
if err := gitea.UnrequestReview(repo.Owner.UserName, repo.Name, id, reviewers...); err != nil {
|
||||
LogError("Cannot unrequest reviews in PR:", repo.Owner.UserName, repo.Name, id, reviewers, ": ", err)
|
||||
}
|
||||
|
||||
// PrjGit already merged above, so skip here.
|
||||
if rs.IsPrjGitPR(prinfo.PR) {
|
||||
continue
|
||||
}
|
||||
git.GitExecOrPanic("", "clone", prinfo.PR.Base.Repo.SSHURL, prinfo.PR.Base.Name)
|
||||
git.GitExecOrPanic(prinfo.PR.Base.Name, "fetch", "origin", prinfo.PR.Head.Sha)
|
||||
git.GitExecOrPanic(prinfo.PR.Base.Name, "merge", "--ff", prinfo.PR.Head.Sha)
|
||||
prinfo.RemoteName, err = git.GitClone(repo.Name, rs.Config.Branch, repo.SSHURL)
|
||||
PanicOnError(err)
|
||||
git.GitExecOrPanic(repo.Name, "fetch", prinfo.RemoteName, head.Sha)
|
||||
git.GitExecOrPanic(repo.Name, "merge", "--ff", head.Sha)
|
||||
|
||||
}
|
||||
|
||||
// push changes
|
||||
git.GitExecOrPanic(DefaultGitPrj, "push", "origin")
|
||||
if !IsDryRun {
|
||||
git.GitExecOrPanic(DefaultGitPrj, "push", remote)
|
||||
} else {
|
||||
LogInfo("*** WOULD push", DefaultGitPrj, "changes to", remote)
|
||||
}
|
||||
for _, prinfo := range rs.PRs {
|
||||
if rs.IsPrjGitPR(prinfo.PR) {
|
||||
continue
|
||||
}
|
||||
git.GitExecOrPanic(prinfo.PR.Base.Name, "push", "origin")
|
||||
repo := prinfo.PR.Base.Repo
|
||||
|
||||
if !IsDryRun {
|
||||
git.GitExecOrPanic(repo.Name, "push", prinfo.RemoteName)
|
||||
} else {
|
||||
LogInfo("*** WOULD push", repo.Name, "to", prinfo.RemoteName)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -14,6 +15,37 @@ import (
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
mock_common "src.opensuse.org/autogits/common/mock"
|
||||
)
|
||||
/*
|
||||
func TestCockpit(t *testing.T) {
|
||||
common.SetLoggingLevel(common.LogLevelDebug)
|
||||
gitea := common.AllocateGiteaTransport("https://src.opensuse.org")
|
||||
tl, err := gitea.GetTimeline("cockpit", "cockpit", 29)
|
||||
if err != nil {
|
||||
t.Fatal("Fail to timeline", err)
|
||||
}
|
||||
t.Log(tl)
|
||||
r, err := common.FetchGiteaReviews(gitea, []string{}, "cockpit", "cockpit", 29)
|
||||
if err != nil {
|
||||
t.Fatal("Error:", err)
|
||||
}
|
||||
|
||||
t.Error(r)
|
||||
}
|
||||
*/
|
||||
func reviewsToTimeline(reviews []*models.PullReview) []*models.TimelineComment {
|
||||
timeline := make([]*models.TimelineComment, len(reviews))
|
||||
for idx, review := range reviews {
|
||||
if review.ID == 0 {
|
||||
review.ID = int64(idx) + 100
|
||||
}
|
||||
|
||||
timeline[idx] = &models.TimelineComment{
|
||||
Type: common.TimelineCommentType_Review,
|
||||
ReviewID: review.ID,
|
||||
}
|
||||
}
|
||||
return timeline
|
||||
}
|
||||
|
||||
func TestPR(t *testing.T) {
|
||||
baseConfig := common.AutogitConfig{
|
||||
@@ -27,6 +59,7 @@ func TestPR(t *testing.T) {
|
||||
pr *models.PullRequest
|
||||
pr_err error
|
||||
reviews []*models.PullReview
|
||||
timeline []*models.TimelineComment
|
||||
review_error error
|
||||
}
|
||||
|
||||
@@ -40,26 +73,26 @@ func TestPR(t *testing.T) {
|
||||
consistentSet bool
|
||||
prjGitPRIndex int
|
||||
|
||||
reviewSetFetcher func(*mock_common.MockGiteaPRFetcher) (*common.PRSet, error)
|
||||
reviewSetFetcher func(*mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error)
|
||||
}{
|
||||
{
|
||||
name: "Error fetching PullRequest",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}, pr_err: errors.New("Missing PR")},
|
||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}, pr_err: errors.New("Missing PR")},
|
||||
},
|
||||
prjGitPRIndex: -1,
|
||||
},
|
||||
{
|
||||
name: "Error fetching PullRequest in PrjGit",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}, pr_err: errors.New("missing PR")},
|
||||
{pr: &models.PullRequest{Body: "", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}, pr_err: errors.New("missing PR")},
|
||||
{pr: &models.PullRequest{Body: "", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, State: "opened"}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Error fetching prjgit",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
},
|
||||
resLen: 1,
|
||||
prjGitPRIndex: -1,
|
||||
@@ -67,8 +100,8 @@ func TestPR(t *testing.T) {
|
||||
{
|
||||
name: "Review set is consistent",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, State: "opened"}},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 1,
|
||||
@@ -78,8 +111,8 @@ func TestPR(t *testing.T) {
|
||||
{
|
||||
name: "Review set is consistent: 1pkg",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, State: "opened"}},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 1,
|
||||
@@ -88,9 +121,9 @@ func TestPR(t *testing.T) {
|
||||
{
|
||||
name: "Review set is consistent: 2pkg",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "some desc", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42\nPR: test/repo2#41", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||
{pr: &models.PullRequest{Body: "some other desc\nPR: foo/fer#33", Index: 41, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo2", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "some desc", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42\nPR: test/repo2#41", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "some other desc\nPR: foo/fer#33", Index: 41, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo2", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
},
|
||||
resLen: 3,
|
||||
prjGitPRIndex: 1,
|
||||
@@ -100,7 +133,7 @@ func TestPR(t *testing.T) {
|
||||
name: "Review set of prjgit PR is consistent",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}},
|
||||
pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
@@ -112,38 +145,385 @@ func TestPR(t *testing.T) {
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: true,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet(mock, "foo", "barPrj", 42, &baseConfig)
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &baseConfig)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Review set is consistent: 2pkg",
|
||||
data: []prdata{
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#222", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo2#41", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42\nPR: test/repo2#41", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#20", Index: 41, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo2", Owner: &models.User{UserName: "test"}}}}},
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#222", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo2#41", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "PR: test/repo#42\nPR: test/repo2#41", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, State: "opened"}},
|
||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#20", Index: 41, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo2", Owner: &models.User{UserName: "test"}}}, State: "opened"}},
|
||||
},
|
||||
resLen: 3,
|
||||
prjGitPRIndex: 2,
|
||||
consistentSet: true,
|
||||
},
|
||||
{
|
||||
name: "WIP PR is not approved",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "", Title: "WIP: some title", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 1,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: false,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &baseConfig)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review is missing",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: false,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review is done, via PrjGit",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "merge ok", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: true,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review is done, via PrjGit",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "merge ok", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: true,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
ManualMergeProject: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review is not done, via PrjGit",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "merge ok", User: &models.User{UserName: "notm2"}, State: common.ReviewStateApproved},
|
||||
{Body: "merge not ok", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: false,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
ManualMergeProject: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review is done via PackageGit",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "Merge ok", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 2,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: true,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review done via PkgGits",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20\nPR: foo/repo#21", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "Merge OK!", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 21, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "merge ok", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 3,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: true,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review done via PkgGits not allowed",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20\nPR: foo/repo#21", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "Merge OK!", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 21, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "merge ok", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 3,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: false,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
ManualMergeProject: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Manual review is is missing on one PR",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/repo#20\nPR: foo/repo#21", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 20, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
{
|
||||
pr: &models.PullRequest{Body: "PR: foo/barPrj#42", Index: 21, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super1"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 3,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: false,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
ManualMergeOnly: true,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "PR is approved with negative optional review",
|
||||
data: []prdata{
|
||||
{
|
||||
pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}, User: &models.User{UserName: "submitter"}, State: "opened"},
|
||||
reviews: []*models.PullReview{
|
||||
{Body: "LGTM", User: &models.User{UserName: "m2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "super2"}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: common.Bot_BuildReview}, State: common.ReviewStateApproved},
|
||||
{Body: "LGTM", User: &models.User{UserName: "bot"}, State: common.ReviewStateRequestChanges},
|
||||
},
|
||||
},
|
||||
},
|
||||
resLen: 1,
|
||||
prjGitPRIndex: 0,
|
||||
consistentSet: true,
|
||||
reviewed: true,
|
||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRTimelineFetcher) (*common.PRSet, error) {
|
||||
config := common.AutogitConfig{
|
||||
Reviewers: []string{"+super1", "*super2", "m1", "-m2", "~*bot"},
|
||||
Branch: "branch",
|
||||
Organization: "foo",
|
||||
GitProjectName: "barPrj",
|
||||
}
|
||||
return common.FetchPRSet("test", mock, "foo", "barPrj", 42, &config)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
pr_mock := mock_common.NewMockGiteaPRFetcher(ctl)
|
||||
pr_mock := mock_common.NewMockGiteaPRTimelineFetcher(ctl)
|
||||
review_mock := mock_common.NewMockGiteaPRChecker(ctl)
|
||||
// reviewer_mock := mock_common.NewMockGiteaReviewRequester(ctl)
|
||||
|
||||
if test.reviewSetFetcher == nil { // if we are fetching the prjgit directly, the these mocks are not called
|
||||
if test.prjGitPRIndex >= 0 {
|
||||
pr_mock.EXPECT().GetAssociatedPrjGitPR(baseConfig.Organization, baseConfig.GitProjectName, test.data[0].pr.Base.Repo.Owner.UserName, test.data[0].pr.Base.Repo.Name, test.data[0].pr.Index).
|
||||
pr_mock.EXPECT().GetPullRequest(baseConfig.Organization, baseConfig.GitProjectName, test.prjGitPRIndex).
|
||||
Return(test.data[test.prjGitPRIndex].pr, test.data[test.prjGitPRIndex].pr_err)
|
||||
} else if test.prjGitPRIndex < 0 {
|
||||
// no prjgit PR
|
||||
pr_mock.EXPECT().GetAssociatedPrjGitPR(baseConfig.Organization, baseConfig.GitProjectName, test.data[0].pr.Base.Repo.Owner.UserName, test.data[0].pr.Base.Repo.Name, test.data[0].pr.Index).
|
||||
pr_mock.EXPECT().GetPullRequest(baseConfig.Organization, baseConfig.GitProjectName, gomock.Any()).
|
||||
Return(nil, nil)
|
||||
}
|
||||
}
|
||||
@@ -155,6 +535,10 @@ func TestPR(t *testing.T) {
|
||||
test_err = data.pr_err
|
||||
}
|
||||
review_mock.EXPECT().GetPullRequestReviews(data.pr.Base.Repo.Owner.UserName, data.pr.Base.Repo.Name, data.pr.Index).Return(data.reviews, data.review_error).AnyTimes()
|
||||
if data.timeline == nil {
|
||||
data.timeline = reviewsToTimeline(data.reviews)
|
||||
}
|
||||
review_mock.EXPECT().GetTimeline(data.pr.Base.Repo.Owner.UserName, data.pr.Base.Repo.Name, data.pr.Index).Return(data.timeline, nil).AnyTimes()
|
||||
}
|
||||
|
||||
var res *common.PRSet
|
||||
@@ -163,7 +547,7 @@ func TestPR(t *testing.T) {
|
||||
if test.reviewSetFetcher != nil {
|
||||
res, err = test.reviewSetFetcher(pr_mock)
|
||||
} else {
|
||||
res, err = common.FetchPRSet(pr_mock, "test", "repo", 42, &baseConfig)
|
||||
res, err = common.FetchPRSet("test", pr_mock, "test", "repo", 42, &baseConfig)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -198,7 +582,7 @@ func TestPR(t *testing.T) {
|
||||
pr_found := false
|
||||
if test.prjGitPRIndex >= 0 {
|
||||
for i := range test.data {
|
||||
if PrjGitPR == test.data[i].pr && i == test.prjGitPRIndex {
|
||||
if PrjGitPR.PR == test.data[i].pr && i == test.prjGitPRIndex {
|
||||
t.Log("found at index", i)
|
||||
pr_found = true
|
||||
}
|
||||
@@ -222,7 +606,9 @@ func TestPR(t *testing.T) {
|
||||
*/
|
||||
|
||||
maintainers := mock_common.NewMockMaintainershipData(ctl)
|
||||
maintainers.EXPECT().IsApproved(gomock.Any(), gomock.Any()).Return(true).AnyTimes()
|
||||
maintainers.EXPECT().ListPackageMaintainers(gomock.Any()).Return([]string{}).AnyTimes()
|
||||
maintainers.EXPECT().ListProjectMaintainers().Return([]string{}).AnyTimes()
|
||||
maintainers.EXPECT().IsApproved(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).AnyTimes()
|
||||
|
||||
if isApproved := res.IsApproved(review_mock, maintainers); isApproved != test.reviewed {
|
||||
t.Error("expected reviewed to be NOT", isApproved)
|
||||
@@ -242,8 +628,10 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
reviewer string
|
||||
}
|
||||
|
||||
pkgReviews []*models.PullReview
|
||||
prjReviews []*models.PullReview
|
||||
pkgReviews []*models.PullReview
|
||||
pkgTimeline []*models.TimelineComment
|
||||
prjReviews []*models.PullReview
|
||||
prjTimeline []*models.TimelineComment
|
||||
|
||||
expectedReviewerCall [2][]string
|
||||
}{
|
||||
@@ -331,8 +719,8 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
},
|
||||
pkgReviews: []*models.PullReview{
|
||||
{
|
||||
State: common.ReviewStateApproved,
|
||||
User: &models.User{UserName: "user2"},
|
||||
State: common.ReviewStateApproved,
|
||||
User: &models.User{UserName: "user2"},
|
||||
},
|
||||
{
|
||||
State: common.ReviewStatePending,
|
||||
@@ -353,15 +741,59 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
},
|
||||
expectedReviewerCall: [2][]string{{"user1", "autogits_obs_staging_bot"}, {"pkgmaintainer"}},
|
||||
},
|
||||
{
|
||||
name: "Stale optional review is not done, re-request it",
|
||||
config: common.AutogitConfig{
|
||||
GitProjectName: "repo",
|
||||
Organization: "org",
|
||||
Branch: "main",
|
||||
Reviewers: []string{"-user1", "user2", "~bot"},
|
||||
},
|
||||
pkgReviews: []*models.PullReview{
|
||||
{
|
||||
State: common.ReviewStateApproved,
|
||||
User: &models.User{UserName: "bot"},
|
||||
Stale: true,
|
||||
},
|
||||
{
|
||||
State: common.ReviewStateApproved,
|
||||
User: &models.User{UserName: "user2"},
|
||||
},
|
||||
{
|
||||
State: common.ReviewStatePending,
|
||||
User: &models.User{UserName: "prjmaintainer"},
|
||||
},
|
||||
},
|
||||
prjReviews: []*models.PullReview{
|
||||
{
|
||||
State: common.ReviewStateRequestChanges,
|
||||
User: &models.User{UserName: "user1"},
|
||||
Stale: true,
|
||||
},
|
||||
{
|
||||
State: common.ReviewStateRequestReview,
|
||||
Stale: true,
|
||||
User: &models.User{UserName: "autogits_obs_staging_bot"},
|
||||
},
|
||||
},
|
||||
expectedReviewerCall: [2][]string{{"user1", "autogits_obs_staging_bot"}, {"pkgmaintainer", "bot"}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
pr_mock := mock_common.NewMockGiteaPRFetcher(ctl)
|
||||
pr_mock := mock_common.NewMockGiteaPRTimelineFetcher(ctl)
|
||||
review_mock := mock_common.NewMockGiteaReviewFetcherAndRequester(ctl)
|
||||
maintainership_mock := mock_common.NewMockMaintainershipData(ctl)
|
||||
|
||||
if test.pkgTimeline == nil {
|
||||
test.pkgTimeline = reviewsToTimeline(test.pkgReviews)
|
||||
}
|
||||
if test.prjTimeline == nil {
|
||||
test.prjTimeline = reviewsToTimeline(test.prjReviews)
|
||||
}
|
||||
|
||||
pr_mock.EXPECT().GetPullRequest("other", "pkgrepo", int64(1)).Return(&models.PullRequest{
|
||||
Body: "Some description is here",
|
||||
User: &models.User{UserName: "submitter"},
|
||||
@@ -371,7 +803,8 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
Index: 1,
|
||||
}, nil)
|
||||
review_mock.EXPECT().GetPullRequestReviews("other", "pkgrepo", int64(1)).Return(test.pkgReviews, nil)
|
||||
pr_mock.EXPECT().GetAssociatedPrjGitPR("org", "repo", "other", "pkgrepo", int64(1)).Return(&models.PullRequest{
|
||||
review_mock.EXPECT().GetTimeline("other", "pkgrepo", int64(1)).Return(test.pkgTimeline, nil)
|
||||
pr_mock.EXPECT().GetPullRequest("org", "repo", int64(1)).Return(&models.PullRequest{
|
||||
Body: fmt.Sprintf(common.PrPattern, "other", "pkgrepo", 1),
|
||||
User: &models.User{UserName: "bot1"},
|
||||
RequestedReviewers: []*models.User{{UserName: "main_reviewer"}},
|
||||
@@ -380,11 +813,12 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
Index: 42,
|
||||
}, nil)
|
||||
review_mock.EXPECT().GetPullRequestReviews("org", "repo", int64(42)).Return(test.prjReviews, nil)
|
||||
review_mock.EXPECT().GetTimeline("org", "repo", int64(42)).Return(test.prjTimeline, nil)
|
||||
|
||||
maintainership_mock.EXPECT().ListProjectMaintainers().Return([]string{"prjmaintainer"}).AnyTimes()
|
||||
maintainership_mock.EXPECT().ListPackageMaintainers("pkgrepo").Return([]string{"pkgmaintainer"}).AnyTimes()
|
||||
|
||||
prs, _ := common.FetchPRSet(pr_mock, "other", "pkgrepo", int64(1), &test.config)
|
||||
prs, _ := common.FetchPRSet("test", pr_mock, "other", "pkgrepo", int64(1), &test.config)
|
||||
if len(prs.PRs) != 2 {
|
||||
t.Fatal("PRs not fetched")
|
||||
}
|
||||
@@ -393,8 +827,9 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
if !prs.IsPrjGitPR(pr.PR) {
|
||||
r = test.expectedReviewerCall[1]
|
||||
}
|
||||
if len(r) > 0 {
|
||||
review_mock.EXPECT().RequestReviews(pr.PR, r).Return(nil, nil)
|
||||
slices.Sort(r)
|
||||
for _, reviewer := range r {
|
||||
review_mock.EXPECT().RequestReviews(pr.PR, reviewer).Return(nil, nil)
|
||||
}
|
||||
}
|
||||
prs.AssignReviewers(review_mock, maintainership_mock)
|
||||
@@ -428,7 +863,7 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
for _, test := range prjgit_tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
pr_mock := mock_common.NewMockGiteaPRFetcher(ctl)
|
||||
pr_mock := mock_common.NewMockGiteaPRTimelineFetcher(ctl)
|
||||
review_mock := mock_common.NewMockGiteaReviewFetcherAndRequester(ctl)
|
||||
maintainership_mock := mock_common.NewMockMaintainershipData(ctl)
|
||||
|
||||
@@ -441,10 +876,11 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
Index: 1,
|
||||
}, nil)
|
||||
review_mock.EXPECT().GetPullRequestReviews("org", "repo", int64(1)).Return(test.prjReviews, nil)
|
||||
review_mock.EXPECT().GetTimeline("org", "repo", int64(1)).Return(nil, nil)
|
||||
|
||||
maintainership_mock.EXPECT().ListProjectMaintainers().Return([]string{"prjmaintainer"}).AnyTimes()
|
||||
|
||||
prs, _ := common.FetchPRSet(pr_mock, "org", "repo", int64(1), &test.config)
|
||||
prs, _ := common.FetchPRSet("test", pr_mock, "org", "repo", int64(1), &test.config)
|
||||
if len(prs.PRs) != 1 {
|
||||
t.Fatal("PRs not fetched")
|
||||
}
|
||||
@@ -453,8 +889,8 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
if !prs.IsPrjGitPR(pr.PR) {
|
||||
t.Fatal("only prjgit pr here")
|
||||
}
|
||||
if len(r) > 0 {
|
||||
review_mock.EXPECT().RequestReviews(pr.PR, r).Return(nil, nil)
|
||||
for _, reviewer := range r {
|
||||
review_mock.EXPECT().RequestReviews(pr.PR, reviewer).Return(nil, nil)
|
||||
}
|
||||
}
|
||||
prs.AssignReviewers(review_mock, maintainership_mock)
|
||||
@@ -463,9 +899,11 @@ func TestPRAssignReviewers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPRMerge(t *testing.T) {
|
||||
repoDir := t.TempDir()
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
cmd := exec.Command("/usr/bin/bash", path.Join(cwd, "test_repo_setup.sh"))
|
||||
cmd.Dir = t.TempDir()
|
||||
cmd := exec.Command(path.Join(cwd, "test_repo_setup.sh"))
|
||||
cmd.Dir = repoDir
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatal(string(out))
|
||||
}
|
||||
@@ -504,7 +942,7 @@ func TestPRMerge(t *testing.T) {
|
||||
Owner: &models.User{
|
||||
UserName: "org",
|
||||
},
|
||||
SSHURL: path.Join(cmd.Dir, "prjgit"),
|
||||
SSHURL: "file://" + path.Join(repoDir, "prjgit"),
|
||||
},
|
||||
},
|
||||
Head: &models.PRBranchInfo{
|
||||
@@ -514,7 +952,7 @@ func TestPRMerge(t *testing.T) {
|
||||
mergeError: "Aborting merge",
|
||||
},
|
||||
{
|
||||
name: "Merge conflict in modules",
|
||||
name: "Merge conflict in modules, auto-resolved",
|
||||
|
||||
pr: &models.PullRequest{
|
||||
Base: &models.PRBranchInfo{
|
||||
@@ -524,7 +962,7 @@ func TestPRMerge(t *testing.T) {
|
||||
Owner: &models.User{
|
||||
UserName: "org",
|
||||
},
|
||||
SSHURL: path.Join(cmd.Dir, "prjgit"),
|
||||
SSHURL: "file://" + path.Join(cmd.Dir, "prjgit"),
|
||||
},
|
||||
},
|
||||
Head: &models.PRBranchInfo{
|
||||
@@ -537,18 +975,79 @@ func TestPRMerge(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mock := mock_common.NewMockGiteaPRFetcher(ctl)
|
||||
mock := mock_common.NewMockGiteaPRTimelineFetcher(ctl)
|
||||
reviewUnrequestMock := mock_common.NewMockGiteaReviewUnrequester(ctl)
|
||||
|
||||
reviewUnrequestMock.EXPECT().UnrequestReview(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
|
||||
|
||||
testDir := t.TempDir()
|
||||
t.Log("dir:", testDir)
|
||||
mock.EXPECT().GetPullRequest("org", "prj", int64(1)).Return(test.pr, nil)
|
||||
|
||||
set, err := common.FetchPRSet(mock, "org", "prj", 1, config)
|
||||
set, err := common.FetchPRSet("test", mock, "org", "prj", 1, config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = set.Merge("test", "test@example.com"); err != nil && (test.mergeError == "" || (len(test.mergeError) > 0 && !strings.Contains(err.Error(), test.mergeError))) {
|
||||
gh, _ := common.AllocateGitWorkTree(testDir, "", "")
|
||||
git, err := gh.CreateGitHandler("org")
|
||||
err = set.Merge(reviewUnrequestMock, git)
|
||||
|
||||
if err != nil && (test.mergeError == "" || (len(test.mergeError) > 0 && !strings.Contains(err.Error(), test.mergeError))) {
|
||||
os.CopyFS("/tmp/upstream", os.DirFS(repoDir))
|
||||
os.CopyFS("/tmp/out", os.DirFS(testDir))
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRChanges(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
PRs []*models.PullRequest
|
||||
PrjPRs *models.PullRequest
|
||||
}{
|
||||
{
|
||||
name: "Pkg PR is closed",
|
||||
PRs: []*models.PullRequest{
|
||||
{
|
||||
Base: &models.PRBranchInfo{Repo: &models.Repository{Owner: &models.User{UserName: "org"}, Name: "repo"}},
|
||||
Index: 42,
|
||||
State: "merged",
|
||||
},
|
||||
},
|
||||
PrjPRs: &models.PullRequest{
|
||||
Title: "some PR",
|
||||
Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "prjgit", Owner: &models.User{UserName: "org"}}},
|
||||
Body: "PR: org/repo#42",
|
||||
State: "opened",
|
||||
},
|
||||
},
|
||||
}
|
||||
config := common.AutogitConfig{
|
||||
Branch: "main",
|
||||
GitProjectName: "org/prjgit#branch",
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mock_fetcher := mock_common.NewMockGiteaPRTimelineFetcher(ctl)
|
||||
mock_fetcher.EXPECT().GetPullRequest("org", "prjgit", int64(42)).Return(test.PrjPRs, nil)
|
||||
for _, pr := range test.PRs {
|
||||
mock_fetcher.EXPECT().GetPullRequest(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index).Return(pr, nil)
|
||||
}
|
||||
|
||||
PRs, err := common.FetchPRSet("user", mock_fetcher, "org", "repo", 42, &config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if PRs.IsConsistent() {
|
||||
t.Fatal("Inconsistent set!")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
238
common/rabbitmq.go
Normal file
238
common/rabbitmq.go
Normal file
@@ -0,0 +1,238 @@
|
||||
package common
|
||||
|
||||
/*
|
||||
* This file is part of Autogits.
|
||||
*
|
||||
* Copyright © 2024 SUSE LLC
|
||||
*
|
||||
* Autogits is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* Autogits is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* Foobar. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
rabbitmq "github.com/rabbitmq/amqp091-go"
|
||||
)
|
||||
|
||||
type RabbitConnection struct {
|
||||
RabbitURL *url.URL // amqps://user:password@host/queue
|
||||
|
||||
queueName string
|
||||
ch *rabbitmq.Channel
|
||||
|
||||
topics []string
|
||||
topicSubChanges chan string // +topic = subscribe, -topic = unsubscribe
|
||||
}
|
||||
|
||||
type RabbitProcessor interface {
|
||||
GenerateTopics() []string
|
||||
|
||||
Connection() *RabbitConnection
|
||||
ProcessRabbitMessage(msg RabbitMessage) error
|
||||
}
|
||||
|
||||
type RabbitMessage rabbitmq.Delivery
|
||||
|
||||
func (l *RabbitConnection) ProcessTopicChanges() {
|
||||
for {
|
||||
topic, ok := <-l.topicSubChanges
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
LogDebug(" topic change:", topic)
|
||||
switch topic[0] {
|
||||
case '+':
|
||||
if err := l.ch.QueueBind(l.queueName, topic[1:], "pubsub", false, nil); err != nil {
|
||||
LogError(err)
|
||||
}
|
||||
case '-':
|
||||
if err := l.ch.QueueUnbind(l.queueName, topic[1:], "pubsub", nil); err != nil {
|
||||
LogError(err)
|
||||
}
|
||||
default:
|
||||
LogInfo("Ignoring unknown topic change:", topic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||
queueName := l.RabbitURL.Path
|
||||
l.RabbitURL.Path = ""
|
||||
|
||||
if len(queueName) > 0 && queueName[0] == '/' {
|
||||
queueName = queueName[1:]
|
||||
}
|
||||
|
||||
connection, err := rabbitmq.DialTLS(l.RabbitURL.String(), &tls.Config{
|
||||
ServerName: l.RabbitURL.Hostname(),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot connect to %s . Err: %w", l.RabbitURL.Hostname(), err)
|
||||
}
|
||||
defer connection.Close()
|
||||
|
||||
l.ch, err = connection.Channel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot create a channel. Err: %w", err)
|
||||
}
|
||||
defer l.ch.Close()
|
||||
|
||||
if err = l.ch.ExchangeDeclarePassive("pubsub", "topic", true, false, false, false, nil); err != nil {
|
||||
return fmt.Errorf("Cannot find pubsub exchange? Err: %w", err)
|
||||
}
|
||||
|
||||
var q rabbitmq.Queue
|
||||
if len(queueName) == 0 {
|
||||
q, err = l.ch.QueueDeclare("", false, true, true, false, nil)
|
||||
} else {
|
||||
q, err = l.ch.QueueDeclarePassive(queueName, true, false, true, false, nil)
|
||||
if err != nil {
|
||||
LogInfo("queue not found .. trying to create it:", err)
|
||||
if l.ch.IsClosed() {
|
||||
l.ch, err = connection.Channel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Channel cannot be re-opened. Err: %w", err)
|
||||
}
|
||||
}
|
||||
q, err = l.ch.QueueDeclare(queueName, true, false, true, false, nil)
|
||||
|
||||
if err != nil {
|
||||
LogInfo("can't create persistent queue ... falling back to temporaty queue:", err)
|
||||
if l.ch.IsClosed() {
|
||||
l.ch, err = connection.Channel()
|
||||
return fmt.Errorf("Channel cannot be re-opened. Err: %w", err)
|
||||
}
|
||||
q, err = l.ch.QueueDeclare("", false, true, true, false, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot declare queue. Err: %w", err)
|
||||
}
|
||||
// log.Printf("queue: %s:%d", q.Name, q.Consumers)
|
||||
|
||||
LogDebug(" -- listening to topics:")
|
||||
l.topicSubChanges = make(chan string)
|
||||
defer close(l.topicSubChanges)
|
||||
go l.ProcessTopicChanges()
|
||||
|
||||
for _, topic := range l.topics {
|
||||
l.topicSubChanges <- "+" + topic
|
||||
}
|
||||
|
||||
msgs, err := l.ch.Consume(q.Name, "", true, true, false, false, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot start consumer. Err: %w", err)
|
||||
}
|
||||
// log.Printf("queue: %s:%d", q.Name, q.Consumers)
|
||||
|
||||
for {
|
||||
msg, ok := <-msgs
|
||||
if !ok {
|
||||
return fmt.Errorf("channel/connection closed?\n")
|
||||
}
|
||||
|
||||
msgCh <- RabbitMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RabbitConnection) ConnectAndProcessRabbitMQ(ch chan<- RabbitMessage) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
LogError(r)
|
||||
LogError("'crash' RabbitMQ worker. Recovering... reconnecting...")
|
||||
time.Sleep(5 * time.Second)
|
||||
go l.ConnectAndProcessRabbitMQ(ch)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
err := l.ProcessRabbitMQ(ch)
|
||||
if err != nil {
|
||||
LogError("Error in RabbitMQ connection. %#v", err)
|
||||
LogInfo("Reconnecting in 2 seconds...")
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RabbitConnection) ConnectToRabbitMQ(processor RabbitProcessor) <-chan RabbitMessage {
|
||||
LogInfo("RabbitMQ connection:", l.RabbitURL.String())
|
||||
|
||||
l.RabbitURL.User = url.UserPassword(rabbitUser, rabbitPassword)
|
||||
l.topics = processor.GenerateTopics()
|
||||
|
||||
ch := make(chan RabbitMessage, 100)
|
||||
go l.ConnectAndProcessRabbitMQ(ch)
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
func (l *RabbitConnection) UpdateTopics(processor RabbitProcessor) {
|
||||
newTopics := processor.GenerateTopics()
|
||||
|
||||
j := 0
|
||||
next_new_topic:
|
||||
for i := 0; i < len(newTopics); i++ {
|
||||
topic := newTopics[i]
|
||||
|
||||
for j < len(l.topics) {
|
||||
cmp := strings.Compare(topic, l.topics[j])
|
||||
|
||||
if cmp == 0 {
|
||||
j++
|
||||
continue next_new_topic
|
||||
}
|
||||
|
||||
if cmp < 0 {
|
||||
l.topicSubChanges <- "+" + topic
|
||||
break
|
||||
}
|
||||
|
||||
l.topicSubChanges <- "-" + l.topics[j]
|
||||
j++
|
||||
}
|
||||
|
||||
if j == len(l.topics) {
|
||||
l.topicSubChanges <- "+" + topic
|
||||
}
|
||||
}
|
||||
|
||||
for j < len(l.topics) {
|
||||
l.topicSubChanges <- "-" + l.topics[j]
|
||||
j++
|
||||
}
|
||||
|
||||
l.topics = newTopics
|
||||
}
|
||||
|
||||
func ProcessRabbitMQEvents(processor RabbitProcessor) error {
|
||||
ch := processor.Connection().ConnectToRabbitMQ(processor)
|
||||
|
||||
for {
|
||||
msg, ok := <-ch
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
LogDebug("event:", msg.RoutingKey)
|
||||
if err := processor.ProcessRabbitMessage(msg); err != nil {
|
||||
LogError("Error processing", msg.RoutingKey, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
128
common/rabbitmq_gitea.go
Normal file
128
common/rabbitmq_gitea.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package common
|
||||
|
||||
/*
|
||||
* This file is part of Autogits.
|
||||
*
|
||||
* Copyright © 2024 SUSE LLC
|
||||
*
|
||||
* Autogits is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* Autogits is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* Foobar. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const RequestType_CreateBrachTag = "create"
|
||||
const RequestType_DeleteBranchTag = "delete"
|
||||
const RequestType_Fork = "fork"
|
||||
const RequestType_Issue = "issues"
|
||||
const RequestType_IssueAssign = "issue_assign"
|
||||
const RequestType_IssueComment = "issue_comment"
|
||||
const RequestType_IssueLabel = "issue_label"
|
||||
const RequestType_IssueMilestone = "issue_milestone"
|
||||
const RequestType_Push = "push"
|
||||
const RequestType_Repository = "repository"
|
||||
const RequestType_Release = "release"
|
||||
const RequestType_PR = "pull_request"
|
||||
const RequestType_PRAssign = "pull_request_assign"
|
||||
const RequestType_PRLabel = "pull_request_label"
|
||||
const RequestType_PRComment = "pull_request_comment"
|
||||
const RequestType_PRMilestone = "pull_request_milestone"
|
||||
const RequestType_PRSync = "pull_request_sync"
|
||||
const RequestType_PRReviewAccepted = "pull_request_review_approved"
|
||||
const RequestType_PRReviewRejected = "pull_request_review_rejected"
|
||||
const RequestType_PRReviewRequest = "pull_request_review_request"
|
||||
const RequestType_PRReviewComment = "pull_request_review_comment"
|
||||
const RequestType_Wiki = "wiki"
|
||||
|
||||
type RequestProcessor interface {
|
||||
ProcessFunc(*Request) error
|
||||
}
|
||||
|
||||
type RabbitMQGiteaEventsProcessor struct {
|
||||
Handlers map[string]RequestProcessor
|
||||
Orgs []string
|
||||
|
||||
c *RabbitConnection
|
||||
}
|
||||
|
||||
func (gitea *RabbitMQGiteaEventsProcessor) Connection() *RabbitConnection {
|
||||
if gitea.c == nil {
|
||||
gitea.c = &RabbitConnection{}
|
||||
}
|
||||
return gitea.c
|
||||
}
|
||||
|
||||
func (gitea *RabbitMQGiteaEventsProcessor) GenerateTopics() []string {
|
||||
topics := make([]string, 0, len(gitea.Handlers)*len(gitea.Orgs))
|
||||
scope := "suse"
|
||||
if gitea.c.RabbitURL.Hostname() == "rabbit.opensuse.org" {
|
||||
scope = "opensuse"
|
||||
}
|
||||
|
||||
for _, org := range gitea.Orgs {
|
||||
for requestType, _ := range gitea.Handlers {
|
||||
topics = append(topics, fmt.Sprintf("%s.src.%s.%s.#", scope, org, requestType))
|
||||
}
|
||||
}
|
||||
|
||||
slices.Sort(topics)
|
||||
return slices.Compact(topics)
|
||||
}
|
||||
|
||||
func (gitea *RabbitMQGiteaEventsProcessor) ProcessRabbitMessage(msg RabbitMessage) error {
|
||||
route := strings.Split(msg.RoutingKey, ".")
|
||||
if len(route) > 3 {
|
||||
reqType := route[3]
|
||||
org := route[2]
|
||||
|
||||
if !slices.Contains(gitea.Orgs, org) {
|
||||
LogInfo("Got event for unhandeled org:", org)
|
||||
return nil
|
||||
}
|
||||
|
||||
LogDebug("org:", org, "type:", reqType)
|
||||
if handler, found := gitea.Handlers[reqType]; found {
|
||||
req, err := ParseRequestJSON(reqType, msg.Body)
|
||||
if err != nil {
|
||||
LogError("Error parsing request JSON:", err)
|
||||
return nil
|
||||
} else {
|
||||
LogDebug("processing req", req.Type)
|
||||
// h.Request = req
|
||||
ProcessEvent(handler, req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("Invalid routing key: %s", route)
|
||||
}
|
||||
|
||||
func ProcessEvent(f RequestProcessor, request *Request) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
LogError("panic caught")
|
||||
if err, ok := r.(error); !ok {
|
||||
LogError(err)
|
||||
}
|
||||
LogError(string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
|
||||
if err := f.ProcessFunc(request); err != nil {
|
||||
LogError(err)
|
||||
}
|
||||
}
|
||||
22
common/rabbitmq_obs.go
Normal file
22
common/rabbitmq_obs.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package common
|
||||
|
||||
type RabbitMQObsBuildStatusProcessor struct {
|
||||
c *RabbitConnection
|
||||
}
|
||||
|
||||
func (o *RabbitMQObsBuildStatusProcessor) GenerateTopics() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (o *RabbitMQObsBuildStatusProcessor) Connection() *RabbitConnection {
|
||||
if o.c == nil {
|
||||
o.c = &RabbitConnection{}
|
||||
}
|
||||
|
||||
return o.c
|
||||
}
|
||||
|
||||
func (o *RabbitMQObsBuildStatusProcessor) ProcessRabbitMessage(msg RabbitMessage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
101
common/rabbitmq_test.go
Normal file
101
common/rabbitmq_test.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
handlers []string
|
||||
orgs1, orgs2 []string
|
||||
|
||||
topicDelta []string
|
||||
}{
|
||||
{
|
||||
name: "no handlers, no orgs",
|
||||
},
|
||||
{
|
||||
name: "adding one org",
|
||||
handlers: []string{"foo"},
|
||||
orgs2: []string{"NewOrg"},
|
||||
topicDelta: []string{"+suse.src.NewOrg.foo.#"},
|
||||
},
|
||||
{
|
||||
name: "adding two orgs",
|
||||
handlers: []string{"foo", "bar"},
|
||||
orgs1: []string{"old"},
|
||||
orgs2: []string{"old", "NewOrg", "NewOrg2"},
|
||||
topicDelta: []string{"+suse.src.NewOrg.foo.#", "+suse.src.NewOrg2.foo.#", "+suse.src.NewOrg.bar.#", "+suse.src.NewOrg2.bar.#"},
|
||||
},
|
||||
{
|
||||
name: "adding one org and removing old one",
|
||||
handlers: []string{"foo", "bar"},
|
||||
orgs1: []string{"old"},
|
||||
orgs2: []string{"NewOrg"},
|
||||
topicDelta: []string{"+suse.src.NewOrg.foo.#", "+suse.src.NewOrg.bar.#", "-suse.src.old.foo.#", "-suse.src.old.bar.#"},
|
||||
},
|
||||
{
|
||||
name: "adding one org and removing old one",
|
||||
handlers: []string{"foo", "bar"},
|
||||
orgs1: []string{"NewOrg"},
|
||||
orgs2: []string{"old"},
|
||||
topicDelta: []string{"-suse.src.NewOrg.foo.#", "-suse.src.NewOrg.bar.#", "+suse.src.old.foo.#", "+suse.src.old.bar.#"},
|
||||
},
|
||||
}
|
||||
|
||||
u, _ := url.Parse("amqps://rabbit.example.com")
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
l := &RabbitMQGiteaEventsProcessor{
|
||||
Orgs: test.orgs1,
|
||||
Handlers: make(map[string]RequestProcessor),
|
||||
c: &RabbitConnection{
|
||||
RabbitURL: u,
|
||||
topicSubChanges: make(chan string, len(test.topicDelta)*10),
|
||||
},
|
||||
}
|
||||
|
||||
slices.Sort(test.topicDelta)
|
||||
|
||||
for _, r := range test.handlers {
|
||||
l.Handlers[r] = nil
|
||||
}
|
||||
|
||||
changes := []string{}
|
||||
l.c.UpdateTopics(l)
|
||||
a:
|
||||
for {
|
||||
select {
|
||||
case c := <-l.c.topicSubChanges:
|
||||
changes = append(changes, c)
|
||||
default:
|
||||
changes = []string{}
|
||||
break a
|
||||
}
|
||||
}
|
||||
|
||||
l.Orgs = test.orgs2
|
||||
|
||||
l.c.UpdateTopics(l)
|
||||
changes = []string{}
|
||||
|
||||
b:
|
||||
for {
|
||||
select {
|
||||
case c := <-l.c.topicSubChanges:
|
||||
changes = append(changes, c)
|
||||
default:
|
||||
slices.Sort(changes)
|
||||
break b
|
||||
}
|
||||
}
|
||||
if !slices.Equal(changes, test.topicDelta) {
|
||||
t.Error("got:", changes, " expected:", test.topicDelta)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,14 @@ import (
|
||||
type Commit struct {
|
||||
Id string
|
||||
Message string
|
||||
|
||||
Added []string
|
||||
Removed []string
|
||||
Modified []string
|
||||
}
|
||||
|
||||
type PushWebhookEvent struct {
|
||||
Ref string
|
||||
Total_Commits int
|
||||
Head_Commit Commit
|
||||
Commits []Commit
|
||||
|
||||
@@ -7,21 +7,33 @@ import (
|
||||
type Reviewers struct {
|
||||
Prj []string
|
||||
Pkg []string
|
||||
|
||||
PrjOptional []string
|
||||
PkgOptional []string
|
||||
}
|
||||
|
||||
func ParseReviewers(input []string) *Reviewers {
|
||||
r := &Reviewers{}
|
||||
for _, reviewer := range input {
|
||||
pkg := &r.Pkg
|
||||
prj := &r.Prj
|
||||
|
||||
if reviewer[0] == '~' {
|
||||
pkg = &r.PkgOptional
|
||||
prj = &r.PrjOptional
|
||||
reviewer = reviewer[1:]
|
||||
}
|
||||
|
||||
switch reviewer[0] {
|
||||
case '*':
|
||||
r.Prj = append(r.Prj, reviewer[1:])
|
||||
r.Pkg = append(r.Pkg, reviewer[1:])
|
||||
*prj = append(*prj, reviewer[1:])
|
||||
*pkg = append(*pkg, reviewer[1:])
|
||||
case '-':
|
||||
r.Prj = append(r.Prj, reviewer[1:])
|
||||
*prj = append(*prj, reviewer[1:])
|
||||
case '+':
|
||||
r.Pkg = append(r.Pkg, reviewer[1:])
|
||||
*pkg = append(*pkg, reviewer[1:])
|
||||
default:
|
||||
r.Pkg = append(r.Pkg, reviewer)
|
||||
*pkg = append(*pkg, reviewer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ func TestReviewers(t *testing.T) {
|
||||
name string
|
||||
input []string
|
||||
|
||||
prj []string
|
||||
pkg []string
|
||||
prj []string
|
||||
pkg []string
|
||||
pkg_optional []string
|
||||
prj_optional []string
|
||||
}{
|
||||
{
|
||||
name: "project and package reviewers",
|
||||
@@ -22,6 +24,15 @@ func TestReviewers(t *testing.T) {
|
||||
prj: []string{"5", "7", common.Bot_BuildReview},
|
||||
pkg: []string{"1", "2", "3", "5", "6"},
|
||||
},
|
||||
{
|
||||
name: "optional project and package reviewers",
|
||||
input: []string{"~1", "2", "3", "~*5", "+6", "-7"},
|
||||
|
||||
prj: []string{"7", common.Bot_BuildReview},
|
||||
pkg: []string{"2", "3", "6"},
|
||||
prj_optional: []string{"5"},
|
||||
pkg_optional: []string{"1", "5"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -31,7 +42,13 @@ func TestReviewers(t *testing.T) {
|
||||
t.Error("unexpected return of ForProject():", reviewers.Prj)
|
||||
}
|
||||
if !slices.Equal(reviewers.Pkg, test.pkg) {
|
||||
t.Error("unexpected return of ForProject():", reviewers.Pkg)
|
||||
t.Error("unexpected return of ForPackage():", reviewers.Pkg)
|
||||
}
|
||||
if !slices.Equal(reviewers.PrjOptional, test.prj_optional) {
|
||||
t.Error("unexpected return of ForProjectOptional():", reviewers.Prj)
|
||||
}
|
||||
if !slices.Equal(reviewers.PkgOptional, test.pkg_optional) {
|
||||
t.Error("unexpected return of ForPackageOptional():", reviewers.Pkg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
@@ -9,27 +11,110 @@ import (
|
||||
type PRReviews struct {
|
||||
reviews []*models.PullReview
|
||||
reviewers []string
|
||||
comments []*models.TimelineComment
|
||||
}
|
||||
|
||||
func FetchGiteaReviews(rf GiteaReviewFetcher, reviewers []string, org, repo string, no int64) (*PRReviews, error) {
|
||||
reviews, err := rf.GetPullRequestReviews(org, repo, no)
|
||||
func FetchGiteaReviews(rf GiteaReviewTimelineFetcher, reviewers []string, org, repo string, no int64) (*PRReviews, error) {
|
||||
timeline, err := rf.GetTimeline(org, repo, no)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawReviews, err := rf.GetPullRequestReviews(org, repo, no)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reviews := make([]*models.PullReview, 0, len(reviewers))
|
||||
var comments []*models.TimelineComment
|
||||
|
||||
alreadyHaveUserReview := func(user string) bool {
|
||||
for _, r := range reviews {
|
||||
if r.User != nil && r.User.UserName == user {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
for idx, item := range timeline {
|
||||
if item.Type == TimelineCommentType_Review {
|
||||
for _, r := range rawReviews {
|
||||
if r.ID == item.ReviewID {
|
||||
if !alreadyHaveUserReview(r.User.UserName) {
|
||||
reviews = append(reviews, r)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if item.Type == TimelineCommentType_Comment {
|
||||
comments = append(comments, item)
|
||||
} else if item.Type == TimelineCommentType_PushPull {
|
||||
LogDebug("cut-off", item.Created)
|
||||
timeline = timeline[0:idx]
|
||||
break
|
||||
} else {
|
||||
LogDebug("Unhandled timeline type:", item.Type)
|
||||
}
|
||||
}
|
||||
LogDebug("num comments:", len(comments), "reviews:", len(reviews), len(timeline))
|
||||
|
||||
return &PRReviews{
|
||||
reviews: reviews,
|
||||
reviewers: reviewers,
|
||||
comments: comments,
|
||||
}, nil
|
||||
}
|
||||
|
||||
const ManualMergeOK = "^merge\\s+ok(\\W|$)"
|
||||
|
||||
var merge_ok_regex *regexp.Regexp = regexp.MustCompile(ManualMergeOK)
|
||||
|
||||
func bodyCommandManualMergeOK(body string) bool {
|
||||
lines := SplitLines(body)
|
||||
for _, line := range lines {
|
||||
if merge_ok_regex.MatchString(strings.ToLower(line)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *PRReviews) IsManualMergeOK() bool {
|
||||
for _, c := range r.comments {
|
||||
if c.Updated != c.Created {
|
||||
continue
|
||||
}
|
||||
LogDebug("comment:", c.User.UserName, c.Body)
|
||||
if slices.Contains(r.reviewers, c.User.UserName) {
|
||||
if bodyCommandManualMergeOK(c.Body) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range r.reviews {
|
||||
if c.Updated != c.Submitted {
|
||||
continue
|
||||
}
|
||||
if slices.Contains(r.reviewers, c.User.UserName) {
|
||||
if bodyCommandManualMergeOK(c.Body) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *PRReviews) IsApproved() bool {
|
||||
goodReview := false
|
||||
goodReview := true
|
||||
|
||||
for _, reviewer := range r.reviewers {
|
||||
goodReview = false
|
||||
for _, review := range r.reviews {
|
||||
if review.User.UserName == reviewer && review.State == ReviewStateApproved && !review.Stale {
|
||||
if review.User.UserName == reviewer && review.State == ReviewStateApproved && !review.Stale && !review.Dismissed {
|
||||
LogDebug(" -- found review: ", review.User.UserName)
|
||||
goodReview = true
|
||||
break
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func TestReviews(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
reviews []*models.PullReview
|
||||
timeline []*models.TimelineComment
|
||||
reviewers []string
|
||||
fetchErr error
|
||||
isApproved bool
|
||||
@@ -21,21 +22,21 @@ func TestReviews(t *testing.T) {
|
||||
isPendingByTest1 bool
|
||||
}{
|
||||
{
|
||||
name: "Reviews of unreviews PR",
|
||||
isApproved: false,
|
||||
name: "Reviews of PR with no review requirements",
|
||||
isApproved: true,
|
||||
},
|
||||
{
|
||||
name: "Single reviewer done",
|
||||
reviews: []*models.PullReview{&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}}},
|
||||
reviewers: []string{"user1"},
|
||||
isApproved: true,
|
||||
name: "Single reviewer done",
|
||||
reviews: []*models.PullReview{&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}}},
|
||||
reviewers: []string{"user1"},
|
||||
isApproved: true,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
name: "Two reviewer, one not approved",
|
||||
reviews: []*models.PullReview{&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}}},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
name: "Two reviewer, one not approved",
|
||||
reviews: []*models.PullReview{&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}}},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
@@ -44,8 +45,8 @@ func TestReviews(t *testing.T) {
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}, Stale: true},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
@@ -54,8 +55,8 @@ func TestReviews(t *testing.T) {
|
||||
&models.PullReview{State: common.ReviewStateRequestReview, User: &models.User{UserName: "user1"}},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isPendingByTest1: true,
|
||||
},
|
||||
{
|
||||
@@ -63,9 +64,9 @@ func TestReviews(t *testing.T) {
|
||||
reviews: []*models.PullReview{
|
||||
&models.PullReview{State: common.ReviewStateRequestReview, User: &models.User{UserName: "user1"}, Stale: true},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isPendingByTest1: false,
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isPendingByTest1: false,
|
||||
isReviewedByTest1: false,
|
||||
},
|
||||
{
|
||||
@@ -74,8 +75,18 @@ func TestReviews(t *testing.T) {
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: true,
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: true,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
name: "Two reviewer approved, one is dismissed",
|
||||
reviews: []*models.PullReview{
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}, Dismissed: true},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
@@ -84,9 +95,9 @@ func TestReviews(t *testing.T) {
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
fetchErr: errors.New("System error fetching reviews."),
|
||||
isApproved: true,
|
||||
reviewers: []string{"user1", "user2"},
|
||||
fetchErr: errors.New("System error fetching reviews."),
|
||||
isApproved: true,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
@@ -96,8 +107,23 @@ func TestReviews(t *testing.T) {
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user4"}},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: true,
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: true,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
{
|
||||
name: "Review ignored before push",
|
||||
reviews: []*models.PullReview{
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user1"}, ID: 1001},
|
||||
&models.PullReview{State: common.ReviewStateApproved, User: &models.User{UserName: "user2"}, ID: 1000},
|
||||
},
|
||||
timeline: []*models.TimelineComment{
|
||||
&models.TimelineComment{Type: common.TimelineCommentType_Review, ReviewID: 1001},
|
||||
&models.TimelineComment{Type: common.TimelineCommentType_PushPull},
|
||||
&models.TimelineComment{Type: common.TimelineCommentType_Review, ReviewID: 1000},
|
||||
},
|
||||
reviewers: []string{"user1", "user2"},
|
||||
isApproved: false,
|
||||
isReviewedByTest1: true,
|
||||
},
|
||||
}
|
||||
@@ -105,8 +131,12 @@ func TestReviews(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
rf := mock_common.NewMockGiteaReviewFetcher(ctl)
|
||||
rf := mock_common.NewMockGiteaReviewTimelineFetcher(ctl)
|
||||
|
||||
if test.timeline == nil {
|
||||
test.timeline = reviewsToTimeline(test.reviews)
|
||||
}
|
||||
rf.EXPECT().GetTimeline("test", "pr", int64(1)).Return(test.timeline, nil)
|
||||
rf.EXPECT().GetPullRequestReviews("test", "pr", int64(1)).Return(test.reviews, test.fetchErr)
|
||||
|
||||
reviews, err := common.FetchGiteaReviews(rf, test.reviewers, "test", "pr", 1)
|
||||
|
||||
@@ -113,6 +113,10 @@ func (s *Submodule) parseKeyValue(line string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Submodule) ManifestSubmodulePath(manifest *Manifest) string {
|
||||
return manifest.SubdirForPackage(s.Path)
|
||||
}
|
||||
|
||||
func ParseSubmodulesFile(reader io.Reader) ([]Submodule, error) {
|
||||
data, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
|
||||
63
common/timeline.go
Normal file
63
common/timeline.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
const (
|
||||
TimelineCommentType_ReviewRequested = "review_request"
|
||||
TimelineCommentType_Review = "review"
|
||||
TimelineCommentType_PushPull = "pull_push"
|
||||
TimelineCommentType_PullRequestRef = "pull_ref"
|
||||
TimelineCommentType_DismissReview = "dismiss_review"
|
||||
TimelineCommentType_Comment = "comment"
|
||||
)
|
||||
|
||||
func FetchTimelineSinceLastPush(gitea GiteaTimelineFetcher, headSha, org, repo string, id int64) ([]*models.TimelineComment, error) {
|
||||
timeline, err := gitea.GetTimeline(org, repo, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//{"is_force_push":true,"commit_ids":["36e43509be1b13a1a8fc63a4361405de04cc621ab16935f88968c46193221bb6","732246a48fbc6bac9df16c0b0ca23ce0f6fbabd9990795863b6d1f0ef3f242c8"]}
|
||||
type PullPushData struct {
|
||||
IsForcePush bool `json:"is_force_push"`
|
||||
CommitIds []string `json:"commit_ids"`
|
||||
}
|
||||
|
||||
// trim timeline to last push update or last time review request was requested
|
||||
for i, e := range timeline {
|
||||
if e.Type == TimelineCommentType_PushPull {
|
||||
var push PullPushData
|
||||
if err := json.Unmarshal([]byte(e.Body), &push); err != nil {
|
||||
LogError(err)
|
||||
}
|
||||
|
||||
if slices.Contains(push.CommitIds, headSha) {
|
||||
return timeline[0:i], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return timeline, nil
|
||||
}
|
||||
|
||||
func FetchTimelineSinceReviewRequestOrPush(gitea GiteaTimelineFetcher, groupName, headSha, org, repo string, id int64) ([]*models.TimelineComment, error) {
|
||||
timeline, err := FetchTimelineSinceLastPush(gitea, headSha, org, repo, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// trim timeline to last push update or last time review request was requested
|
||||
for i, e := range timeline {
|
||||
if e.Type == TimelineCommentType_ReviewRequested && e.Assignee != nil && e.Assignee.UserName == groupName {
|
||||
// review request is cut-off for reviews too
|
||||
return timeline[0:i], nil
|
||||
}
|
||||
}
|
||||
|
||||
return timeline, nil
|
||||
}
|
||||
138
common/utils.go
138
common/utils.go
@@ -19,11 +19,22 @@ package common
|
||||
*/
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
func SplitLines(str string) []string {
|
||||
return SplitStringNoEmpty(str, "\n")
|
||||
}
|
||||
|
||||
func SplitStringNoEmpty(str, sep string) []string {
|
||||
ret := slices.DeleteFunc(strings.Split(str, sep), func(s string) bool {
|
||||
return len(strings.TrimSpace(s)) == 0
|
||||
@@ -35,16 +46,131 @@ func SplitStringNoEmpty(str, sep string) []string {
|
||||
}
|
||||
|
||||
func TranslateHttpsToSshUrl(url string) (string, error) {
|
||||
const url1 = "https://src.opensuse.org/"
|
||||
const url2 = "https://src.suse.de/"
|
||||
const (
|
||||
url1 = "https://src.opensuse.org/"
|
||||
url2 = "https://src.suse.de/"
|
||||
|
||||
if len(url) > len(url1) && url[0:len(url1)] == url1 {
|
||||
return "gitea@src.opensuse.org:" + url[len(url1):], nil
|
||||
url1_len = len(url1)
|
||||
url2_len = len(url2)
|
||||
)
|
||||
|
||||
if len(url) > url1_len && url[0:url1_len] == url1 {
|
||||
return "ssh://gitea@src.opensuse.org/" + url[url1_len:], nil
|
||||
}
|
||||
if len(url) > len(url2) && url[0:len(url2)] == url2 {
|
||||
return "gitea@src.suse.de:" + url[len(url2):], nil
|
||||
if len(url) > url2_len && url[0:url2_len] == url2 {
|
||||
return "ssh://gitea@src.suse.de/" + url[url2_len:], nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("Unknown input url %s", url)
|
||||
}
|
||||
|
||||
func TranslateSshNativeToUrl(urlString string) (string, error) {
|
||||
rx := regexp.MustCompile("^([^:@]+)@?([^:]*):(.+)$")
|
||||
m := rx.FindAllStringSubmatch(urlString, -1)
|
||||
if m == nil {
|
||||
return "", fmt.Errorf("Cannot match expected native SSH schema: %s", urlString)
|
||||
}
|
||||
|
||||
if len(m[0][2]) > 0 {
|
||||
// with user
|
||||
return "ssh://" + m[0][1] + "@" + m[0][2] + "/" + m[0][3], nil
|
||||
}
|
||||
// without user
|
||||
return "ssh://" + m[0][1] + "/" + m[0][3], nil
|
||||
}
|
||||
|
||||
type GitUrl struct {
|
||||
Org string
|
||||
Repo string
|
||||
Commit string
|
||||
}
|
||||
|
||||
var valid_schemas []string = []string{"https", "ssh", "http", "file"}
|
||||
|
||||
func ParseGitRemoteUrl(urlString string) (*GitUrl, error) {
|
||||
url, err := url.Parse(urlString)
|
||||
|
||||
if url != nil && url.Scheme == "file" && err == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err != nil || !slices.Contains(valid_schemas, url.Scheme) {
|
||||
u, err := TranslateSshNativeToUrl(urlString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse url: %w", err)
|
||||
}
|
||||
return ParseGitRemoteUrl(u)
|
||||
}
|
||||
|
||||
e := SplitStringNoEmpty(url.Path, "/")
|
||||
if len(e) != 2 {
|
||||
return nil, fmt.Errorf("Unexpected format for Gitea URL: %s", e)
|
||||
}
|
||||
|
||||
org := e[0]
|
||||
repo := strings.TrimSuffix(e[1], ".git")
|
||||
|
||||
u := GitUrl{
|
||||
Org: org,
|
||||
Repo: repo,
|
||||
Commit: url.Fragment,
|
||||
}
|
||||
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
func (giturl *GitUrl) RemoteName() string {
|
||||
if giturl == nil || len(giturl.Org) == 0 || len(giturl.Repo) == 0 {
|
||||
return "origin"
|
||||
}
|
||||
|
||||
return strings.ToLower(giturl.Org) + "_" + strings.ToLower(giturl.Repo)
|
||||
}
|
||||
|
||||
func PRtoString(pr *models.PullRequest) string {
|
||||
if pr == nil {
|
||||
return "(null)"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/%s#%d", pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index)
|
||||
}
|
||||
|
||||
type DevelProject struct {
|
||||
Project, Package string
|
||||
}
|
||||
|
||||
type DevelProjects []*DevelProject
|
||||
|
||||
func FetchDevelProjects() (DevelProjects, error) {
|
||||
res, err := http.Get("https://src.opensuse.org/openSUSE/Factory/raw/branch/main/pkgs/_meta/devel_packages")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
scanner := bufio.NewScanner(res.Body)
|
||||
ret := []*DevelProject{}
|
||||
for scanner.Scan() {
|
||||
d := SplitStringNoEmpty(scanner.Text(), " ")
|
||||
if len(d) == 2 {
|
||||
ret = append(ret, &DevelProject{
|
||||
Project: d[1],
|
||||
Package: d[0],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
var DevelProjectNotFound = errors.New("Devel project not found")
|
||||
func (d DevelProjects) GetDevelProject(pkg string) (string, error) {
|
||||
for _, item := range d {
|
||||
if item.Package == pkg {
|
||||
return item.Project, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", DevelProjectNotFound
|
||||
}
|
||||
|
||||
|
||||
167
common/utils_test.go
Normal file
167
common/utils_test.go
Normal file
@@ -0,0 +1,167 @@
|
||||
package common_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"src.opensuse.org/autogits/common"
|
||||
)
|
||||
|
||||
func TestGitUrlParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
inputUrl string
|
||||
url common.GitUrl
|
||||
|
||||
error bool
|
||||
}{
|
||||
{
|
||||
name: "Empty string",
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
name: "OpenSUSE HTTPS Url",
|
||||
url: common.GitUrl{
|
||||
Org: "foo",
|
||||
Repo: "b",
|
||||
},
|
||||
inputUrl: "https://src.opensuse.org/foo/b.git",
|
||||
},
|
||||
{
|
||||
name: "OpenSUSE HTTPS Url",
|
||||
url: common.GitUrl{
|
||||
Org: "a",
|
||||
Repo: "b",
|
||||
},
|
||||
inputUrl: "https://src.opensuse.org/a/b",
|
||||
},
|
||||
{
|
||||
name: "OpenSUSE HTTPS Url",
|
||||
url: common.GitUrl{
|
||||
Org: "foo",
|
||||
Repo: "bar",
|
||||
Commit: "main",
|
||||
},
|
||||
inputUrl: "https://src.opensuse.org/foo/bar.git#main",
|
||||
},
|
||||
{
|
||||
name: "invalid OpenSUSE HTTPS Url",
|
||||
inputUrl: "https://src.opensuse.org/bar.git#main",
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
name: "OpenSUSE SSH Url",
|
||||
url: common.GitUrl{
|
||||
Org: "foo",
|
||||
Repo: "bar",
|
||||
Commit: "main",
|
||||
},
|
||||
inputUrl: "ssh://src.opensuse.org/foo/bar.git#main",
|
||||
},
|
||||
{
|
||||
name: "SSH native OpenSUSE Url",
|
||||
inputUrl: "gitea@src.opensuse.org:foo/bar.git#main",
|
||||
url: common.GitUrl{
|
||||
Org: "foo",
|
||||
Repo: "bar",
|
||||
Commit: "main",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "SSH native OpenSUSE Url without user",
|
||||
inputUrl: "src.opensuse.org:foo/bar.git#main",
|
||||
url: common.GitUrl{
|
||||
Org: "foo",
|
||||
Repo: "bar",
|
||||
Commit: "main",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid SSH native OpenSUSE Url without user",
|
||||
inputUrl: "src.opensuse.org:/br.it",
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
name: "SSH native OpenSUSE Url without user",
|
||||
inputUrl: "src.opensuse.org:foo/bar#main",
|
||||
url: common.GitUrl{
|
||||
Org: "foo",
|
||||
Repo: "bar",
|
||||
Commit: "main",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
url, err := common.ParseGitRemoteUrl(test.inputUrl)
|
||||
if test.error && err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if test.error && err == nil {
|
||||
t.Fatal("Expected an error but received", *url)
|
||||
} else if !test.error && err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if url == nil {
|
||||
t.Fatal("Recieved nil. Expected", test.url)
|
||||
} else if *url != test.url {
|
||||
t.Fatalf("Expected %v but received %v", test.url, *url)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
giturl *common.GitUrl
|
||||
remotename string
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
remotename: "origin",
|
||||
},
|
||||
{
|
||||
name: "regular repo",
|
||||
giturl: &common.GitUrl{
|
||||
Org: "org1",
|
||||
Repo: "repo2",
|
||||
Commit: "main",
|
||||
},
|
||||
remotename: "org1_repo2",
|
||||
},
|
||||
{
|
||||
name: "regular repo with upper case",
|
||||
giturl: &common.GitUrl{
|
||||
Org: "Org1",
|
||||
Repo: "REPO2",
|
||||
},
|
||||
remotename: "org1_repo2",
|
||||
},
|
||||
{
|
||||
name: "no org",
|
||||
giturl: &common.GitUrl{
|
||||
Repo: "REPO2",
|
||||
},
|
||||
remotename: "origin",
|
||||
},
|
||||
{
|
||||
name: "no repo",
|
||||
giturl: &common.GitUrl{
|
||||
Org: "ORG2",
|
||||
},
|
||||
remotename: "origin",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
n := test.giturl.RemoteName()
|
||||
if n != test.remotename {
|
||||
t.Errorf("Expected '%s' but received '%s'", test.remotename, n)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,12 @@ if [ "x$1" = 'x' ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
files=$(find .. -maxdepth 2 -name \*.go -and \! -wholename \*/gitea-generated/\*)
|
||||
|
||||
while true; do
|
||||
go test --run "$1"
|
||||
inotifywait --exclude 'node_modules' -qqr -e close_write .. && clear
|
||||
inotifywait -qqr -e close_write $files
|
||||
clear
|
||||
sleep 0.2
|
||||
done
|
||||
|
||||
|
||||
3
devel-importer/.gitignore
vendored
3
devel-importer/.gitignore
vendored
@@ -1 +1,4 @@
|
||||
devel-importer
|
||||
Factory
|
||||
git
|
||||
git-migrated
|
||||
|
||||
50
devel-importer/attribute-update.sh
Executable file
50
devel-importer/attribute-update.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Factory meta data checked-out
|
||||
export DEVEL_PACKAGES=$PWD/Factory/pkgs/_meta/devel_packages
|
||||
devel=$PWD/devel_update.sh
|
||||
|
||||
function getorg {
|
||||
osc meta prj $1 | grep scmsync | sed -e's,^.*src\.opensuse\.org/,,' -e 's,/_ObsPrj.*$,,'
|
||||
}
|
||||
|
||||
function factory {
|
||||
$devel get $1
|
||||
}
|
||||
|
||||
function message {
|
||||
org=$1
|
||||
pkg=$2
|
||||
dprj=$3
|
||||
echo "This package is developed in git at https://src.opensuse.org/${org}/${pkg} for OBS package ${dprj}/${pkg} -- see https://en.opensuse.org/openSUSE:OBS_to_Git"
|
||||
}
|
||||
|
||||
obs=$1
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
obs=$(cat migrated_projects)
|
||||
fi
|
||||
|
||||
for p in $obs; do
|
||||
org=$(getorg $p)
|
||||
if [ -z "$org" ]; then
|
||||
echo $p is not in git!
|
||||
continue
|
||||
fi
|
||||
|
||||
packages=$(osc ls $p)
|
||||
for pkg in $packages; do
|
||||
dprj=$(factory $pkg)
|
||||
if [ "$dprj" != "$p" ]; then
|
||||
# not devel project
|
||||
continue
|
||||
fi
|
||||
msg=$(message $org $pkg $dprj)
|
||||
|
||||
if [ -n "$msg" ]; then
|
||||
echo $msg
|
||||
osc meta attribute openSUSE:Factory $pkg --attribute OBS:RejectBranch --set "$msg" > /dev/null || exit 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
127
devel-importer/devel_update.sh
Executable file
127
devel-importer/devel_update.sh
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/bash
|
||||
#
|
||||
# Updates devel_packages in https://src.opensuse.org/openSUSE/Factory/src/branch/main/pkgs/_meta/devel_packages
|
||||
#
|
||||
# syntax:
|
||||
# get <pkg>
|
||||
# set <prj> <pkg>
|
||||
# rm <prj> <pkg>
|
||||
# sync
|
||||
#
|
||||
# DEVEL_PACKAGES env should point to the devel_packages clone from
|
||||
# repo above, otherwise will look in CWD
|
||||
#
|
||||
|
||||
set +e
|
||||
|
||||
function getdevel {
|
||||
local pkg="$1"
|
||||
awk "{ if ( \$1 == \"$pkg\" ) print \$2 }" "$DEVEL_PACKAGES"
|
||||
}
|
||||
|
||||
function setdevel {
|
||||
local prj="$1"
|
||||
local pkg="$2"
|
||||
if [ x"$prj" == "x" ] || [ x"$pkg" == "x" ]; then
|
||||
echo "devel_update set <prj> <pkg>"
|
||||
exit 10
|
||||
fi
|
||||
|
||||
cat <(awk "{ if ( \$1 != \"$pkg\" ) print }" "$DEVEL_PACKAGES") <(echo $pkg $prj) | sort -d > "$DEVEL_PACKAGES".$$
|
||||
mv "$DEVEL_PACKAGES".$$ "$DEVEL_PACKAGES"
|
||||
}
|
||||
|
||||
function rmdevel {
|
||||
local prj="$1"
|
||||
local pkg="$2"
|
||||
if [ x"$prj" == "x" ] || [ x"$pkg" == "x" ]; then
|
||||
echo "devel_update rm <prj> <pkg>"
|
||||
exit 10
|
||||
fi
|
||||
|
||||
awk "{ if ( ! ( \$1 == \"$pkg\" && \$2 == \"$prj\" ) ) print }" "$DEVEL_PACKAGES" > "$DEVEL_PACKAGES".$$
|
||||
mv "$DEVEL_PACKAGES".$$ "$DEVEL_PACKAGES"
|
||||
}
|
||||
|
||||
if [ -z "$DEVEL_PACKAGES" ]; then
|
||||
DEVEL_PACKAGES=./devel_packages
|
||||
fi
|
||||
|
||||
if ! [ -w "$DEVEL_PACKAGES" ] || ! [ -e "$DEVEL_PACKAGES" ] ; then
|
||||
echo "The DEVEL_PACKAGES ($DEVEL_PACKAGES) file is not writable or doesn't exist"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
get)
|
||||
shift
|
||||
getdevel "$@"
|
||||
;;
|
||||
set)
|
||||
shift
|
||||
setdevel "$@"
|
||||
;;
|
||||
rm)
|
||||
shift
|
||||
rmdevel "$@"
|
||||
;;
|
||||
sync)
|
||||
warning=0
|
||||
badpkgs=""
|
||||
pkgs=$(osc ls openSUSE:Factory)
|
||||
|
||||
# add new packages
|
||||
for pkg in $pkgs; do
|
||||
if [ "${pkg/*:*/IGNORE}" == "IGNORE" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
grep -q "^$pkg\( \|\$\)" "$DEVEL_PACKAGES"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -n "$pkg -> "
|
||||
devel=$(osc develproject openSUSE:Factory $pkg 2> /dev/null)
|
||||
devel=${devel/\/*/}
|
||||
if [ -z "$devel" ]; then
|
||||
devel=$(osc rq list -s accepted -P openSUSE:Factory -p $pkg -t submit | grep "^\s*submit:.* -> openSUSE:Factory\$" | sed -e "s,^\s*submit:\s*\([^/]\+\)/${pkg}@.*,\1," | uniq)
|
||||
c=$(echo "$devel" | grep -c .)
|
||||
if [ $c -ne 1 ]; then
|
||||
badpkgs="$badpkgs $pkg"
|
||||
warning=1
|
||||
devel="***** UNKNOWN"
|
||||
fi
|
||||
fi
|
||||
|
||||
setdevel "$devel" "$pkg"
|
||||
echo "$devel"
|
||||
fi
|
||||
done
|
||||
|
||||
# remove deleted packages
|
||||
for pkg in $(awk '{ print $1 }' < "$DEVEL_PACKAGES"); do
|
||||
if [[ " $pkgs " != *[[:space:]]"$pkg"[[:space:]]* ]]; then
|
||||
echo "removing $pkg"
|
||||
d=$(getdevel "$pkg")
|
||||
if [ -n "$d" ]; then
|
||||
rmdevel "$d" "$pkg"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# set devel change in last 10 days
|
||||
osc rq list -t change_devel -D 10 -P openSUSE:Factory -s accepted |
|
||||
grep 'change_devel:\s\+openSUSE:Factory/' |
|
||||
sed -e 's,^\s*change_devel:\s*openSUSE:Factory/\([a-zA-Z0-9_+-]\+\)\s*developed in \([a-zA-Z0-9_+:-]\+\)/\1\s*$,\2 \1,' |
|
||||
while read line; do
|
||||
setdevel ${line/ */} ${line/* /};
|
||||
done
|
||||
|
||||
if [ $warning -ne 0 ]; then
|
||||
echo " **** WARNING ****" > /dev/stderr
|
||||
echo "Could not fix some packages. Manual intervention required:$badpkgs" > /dev/stderr
|
||||
fi
|
||||
|
||||
;;
|
||||
*)
|
||||
echo " devel_update (get,set,rm,sync) ...."
|
||||
|
||||
esac
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -73,6 +72,10 @@ func runObsCommand(args ...string) ([]string, error) {
|
||||
|
||||
var DebugMode bool
|
||||
|
||||
func giteaPackage(pkg string) string {
|
||||
return strings.ReplaceAll(pkg, "+", "_")
|
||||
}
|
||||
|
||||
func projectMaintainer(obs *common.ObsClient, prj string) ([]string, []string) { // users, groups
|
||||
meta, err := obs.GetProjectMeta(prj)
|
||||
if err != nil {
|
||||
@@ -154,6 +157,7 @@ func gitImporter(prj, pkg string) error {
|
||||
params = append(params, "-l", "debug")
|
||||
}
|
||||
params = append(params, pkg)
|
||||
common.LogDebug("git-importer", params)
|
||||
cmd := exec.Command("./git-importer", params...)
|
||||
if idx := slices.IndexFunc(cmd.Env, func(val string) bool { return val[0:12] == "GITEA_TOKEN=" }); idx != -1 {
|
||||
cmd.Env = slices.Delete(cmd.Env, idx, idx+1)
|
||||
@@ -166,310 +170,113 @@ func gitImporter(prj, pkg string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func cloneDevel(git common.Git, gitDir, outName, urlString string) error {
|
||||
url, err := url.Parse(urlString)
|
||||
branch := url.Fragment
|
||||
url.Fragment = ""
|
||||
|
||||
params := []string{"clone"}
|
||||
if len(branch) > 0 {
|
||||
params = append(params, "-b", branch)
|
||||
func cloneDevel(git common.Git, gitDir, outName, urlString, remote string, fatal bool) error {
|
||||
if url, _ := url.Parse(urlString); url != nil {
|
||||
url.Fragment = ""
|
||||
urlString = url.String()
|
||||
}
|
||||
params = append(params, url.String(), outName)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing SSH URL. %w", err)
|
||||
params := []string{"clone", "-o", remote}
|
||||
params = append(params, urlString, outName)
|
||||
|
||||
if fatal {
|
||||
git.GitExecOrPanic(gitDir, params...)
|
||||
} else {
|
||||
git.GitExec(gitDir, params...)
|
||||
}
|
||||
git.GitExecOrPanic(gitDir, params...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func importRepos(packages []string) {
|
||||
factoryRepos := make([]*models.Repository, 0, len(packages)*2)
|
||||
develProjectPackages := make([]string, 0, len(packages))
|
||||
for _, pkg := range packages {
|
||||
src_pkg_name := strings.Split(pkg, ":")
|
||||
repo, err := client.Repository.RepoGet(
|
||||
repository.NewRepoGetParams().
|
||||
WithDefaults().WithOwner("pool").WithRepo(src_pkg_name[0]),
|
||||
r.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
log.Println("Cannot find src package:", src_pkg_name)
|
||||
develProjectPackages = append(develProjectPackages, src_pkg_name[0])
|
||||
} else {
|
||||
factoryRepos = append(factoryRepos, repo.Payload)
|
||||
}
|
||||
}
|
||||
log.Println("Num repos found:", len(factoryRepos))
|
||||
|
||||
oldPackageNames := make([]string, 0, len(factoryRepos))
|
||||
for _, repo := range factoryRepos {
|
||||
oldPackageNames = append(oldPackageNames, repo.Name)
|
||||
}
|
||||
|
||||
// fork packags from pool
|
||||
for i := 0; i < len(oldPackageNames); {
|
||||
pkg := oldPackageNames[i]
|
||||
log.Println(" + package:", pkg)
|
||||
if err := gitImporter("openSUSE:Factory", pkg); err != nil {
|
||||
log.Println(" ** failed to import openSUSE:Factory", pkg)
|
||||
log.Println(" ** falling back to devel project only")
|
||||
|
||||
develProjectPackages = append(develProjectPackages, pkg)
|
||||
oldPackageNames = slices.Delete(oldPackageNames, i, i+1)
|
||||
} else {
|
||||
i++
|
||||
func findMissingDevelBranch(git common.Git, pkg, project string) {
|
||||
d, err := git.GitBranchHead(pkg, "devel")
|
||||
if err != nil {
|
||||
if _, err = git.GitBranchHead(pkg, "factory"); err != nil {
|
||||
log.Println("factory is missing... so maybe repo is b0rked.")
|
||||
return
|
||||
}
|
||||
|
||||
hash := common.SplitLines(git.GitExecWithOutputOrPanic(pkg,
|
||||
"log",
|
||||
"factory",
|
||||
"--all",
|
||||
"--grep=build.opensuse.org/package/show/"+project+"/"+pkg,
|
||||
"-1",
|
||||
"--pretty=format:%H"))
|
||||
if len(hash) > 0 {
|
||||
log.Println(" devel @", hash[0])
|
||||
git.GitExecOrPanic(pkg, "branch", "devel", hash[0])
|
||||
} else {
|
||||
git.GitExecOrPanic(pkg, "branch", "devel", "factory")
|
||||
}
|
||||
} else {
|
||||
log.Println(" devel already exists?", d)
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("adding remotes...")
|
||||
for i := 0; i < len(factoryRepos); i++ {
|
||||
pkg := factoryRepos[i]
|
||||
|
||||
// verify that package was created by `git-importer`, or it's scmsync package and clone it
|
||||
fi, err := os.Stat(filepath.Join(git.GetPath(), pkg.Name))
|
||||
if os.IsNotExist(err) {
|
||||
if slices.Contains(develProjectPackages, pkg.Name) {
|
||||
// failed import of former factory package
|
||||
continue
|
||||
}
|
||||
|
||||
// scmsync?
|
||||
devel_project, err := runObsCommand("develproject", "openSUSE:Factory", pkg.Name)
|
||||
if err != nil || len(devel_project) != 1 {
|
||||
log.Panicln("devel project len:", len(devel_project), "for", pkg.Name, "err:", err)
|
||||
}
|
||||
d := strings.Split(devel_project[0], "/")
|
||||
if len(d) != 2 {
|
||||
log.Panicln("expected devel project/package. got:", d)
|
||||
}
|
||||
meta, _ := obs.GetPackageMeta(d[0], d[1])
|
||||
if len(meta.ScmSync) > 0 {
|
||||
if err2 := cloneDevel(git, "", pkg.Name, meta.ScmSync); err != nil {
|
||||
log.Panicln(err2)
|
||||
}
|
||||
git.GitExecOrPanic(pkg.Name, "checkout", "-B", "main")
|
||||
continue
|
||||
}
|
||||
|
||||
// try again, should now exist
|
||||
if fi, err = os.Stat(filepath.Join(git.GetPath(), pkg.Name)); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
} else if err != nil {
|
||||
func importFactoryRepoAndCheckHistory(pkg string, meta *common.PackageMeta) (factoryRepo *models.Repository, retErr error) {
|
||||
if repo, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithDefaults().WithOwner("pool").WithRepo(giteaPackage(pkg)), r.DefaultAuthentication); err != nil {
|
||||
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
||||
log.Panicln(err)
|
||||
} else {
|
||||
// verify that we do not have scmsync for imported packages
|
||||
meta, err := obs.GetPackageMeta(prj, pkg.Name)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if len(meta.ScmSync) > 0 {
|
||||
log.Panicln("importing an scmsync package??:", prj, pkg.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if !fi.IsDir() {
|
||||
log.Panicln("Expected package file should be a directory. It's not.", fi)
|
||||
}
|
||||
log.Println("Cannot find src package:", pkg)
|
||||
return nil, nil
|
||||
} else {
|
||||
factoryRepo = repo.Payload
|
||||
CreatePoolFork(factoryRepo)
|
||||
}
|
||||
|
||||
// add remote repos
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show", "-n")
|
||||
switch pkg.Owner.UserName {
|
||||
case "pool":
|
||||
if !slices.Contains(strings.Split(out, "\n"), "pool") {
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "pool", pkg.CloneURL)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Panicln(pkg.Owner.UserName)
|
||||
if _, err := os.Stat(filepath.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
||||
common.LogDebug("Cloning factory...")
|
||||
cloneDevel(git, "", pkg, factoryRepo.CloneURL, "pool", true) // in case we have imported
|
||||
} else if err != nil {
|
||||
common.PanicOnError(err)
|
||||
} else {
|
||||
// we have already cloned it... so, fetch pool remote
|
||||
common.LogDebug("Fetching pool, as already should have the remote")
|
||||
if err = git.GitExec(pkg, "fetch", "pool"); err != nil {
|
||||
common.LogError(err)
|
||||
return factoryRepo, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkgName := range oldPackageNames {
|
||||
log.Println("fetching git:", pkgName)
|
||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "remote", "show", "-n"), "\n")
|
||||
|
||||
params := []string{"fetch", "--multiple"}
|
||||
params = append(params, remotes...)
|
||||
out, _ := git.GitExecWithOutput(pkgName, params...)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
|
||||
if slices.Contains(remotes, "origin") {
|
||||
log.Println(" --- scmsync already, so we are done")
|
||||
continue
|
||||
}
|
||||
|
||||
// check if devel is ahead or behind factory and use that as reference
|
||||
import_branch := "factory"
|
||||
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "^factory", "devel"), "\n")) > 0 {
|
||||
log.Println(" *** devel ahead. Swtiching branches.")
|
||||
import_branch = "devel"
|
||||
}
|
||||
|
||||
// check that nothing is broken with the update
|
||||
if slices.Contains(remotes, "pool") {
|
||||
// check which branch is ahead
|
||||
branches, err := fs.ReadDir(os.DirFS(path.Join(git.GetPath(), pkgName, ".git/refs/remotes")), "pool")
|
||||
if err != nil {
|
||||
if forceBadPool {
|
||||
log.Println(" *** factory has no branches!!! Treating as a devel package.")
|
||||
develProjectPackages = append(develProjectPackages, pkgName)
|
||||
break
|
||||
} else {
|
||||
log.Panicln(" *** factory has no branches", branches)
|
||||
}
|
||||
}
|
||||
pool_branch := "factory"
|
||||
|
||||
has_factory_devel := false
|
||||
has_factory_factory := false
|
||||
|
||||
for _, branch := range branches {
|
||||
if branch.Name() == "factory" {
|
||||
has_factory_factory = true
|
||||
} else if branch.Name() == "devel" {
|
||||
has_factory_devel = true
|
||||
}
|
||||
}
|
||||
log.Println(branches)
|
||||
|
||||
if has_factory_devel && has_factory_factory {
|
||||
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "^pool/factory", "pool/devel"), "\n")) > 0 {
|
||||
log.Println(" *** pool branch devel ahead. Switching branches.")
|
||||
pool_branch = "devel"
|
||||
}
|
||||
} else if has_factory_devel && !has_factory_factory {
|
||||
pool_branch = "devel"
|
||||
} else if !has_factory_devel && has_factory_factory {
|
||||
|
||||
} else {
|
||||
log.Panicln("branches screwed up for pkg", pkgName, branches)
|
||||
}
|
||||
|
||||
// find tree object in factory branch
|
||||
tree := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "-1", "--format=%T", "--no-commit-header", "pool/"+pool_branch))
|
||||
log.Println("tree", tree)
|
||||
import_tree_commits := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "--format=%H %T", "--no-commit-header", import_branch), "\n")
|
||||
found := false
|
||||
for i := range import_tree_commits {
|
||||
commit_tree := strings.Split(import_tree_commits[i], " ")
|
||||
if len(commit_tree) != 2 {
|
||||
log.Panicln("wrong format?", commit_tree)
|
||||
}
|
||||
if commit_tree[1] == tree {
|
||||
found = true
|
||||
cherry_picks := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "--no-merges", "--reverse", "--ancestry-path", commit_tree[0]+".."+import_branch), "\n")
|
||||
|
||||
log.Println("cherry picks", cherry_picks)
|
||||
git.GitExecOrPanic(pkgName, "checkout", "-B", "main", "pool/"+pool_branch)
|
||||
for _, pick := range cherry_picks {
|
||||
git.GitExecOrPanic(pkgName, "cherry-pick", pick)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
log.Println("*** WARNING: Cannot find same tree for pkg", pkgName, "Will use current import instead")
|
||||
git.GitExecOrPanic(pkgName, "checkout", "-B", "main", "heads/"+import_branch)
|
||||
}
|
||||
} else {
|
||||
git.GitExecOrPanic(pkgName, "checkout", "-B", "main", "heads/"+import_branch)
|
||||
roots := 0
|
||||
if _, err := git.GitBranchHead(pkg, "pool/devel"); err == nil {
|
||||
factory_roots := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "pool/factory", "--max-parents=0"))
|
||||
devel_roots := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "pool/devel", "--max-parents=0"))
|
||||
roots = len(common.SplitLines(factory_roots))
|
||||
if devel_roots != factory_roots || len(common.SplitLines(factory_roots)) != 1 {
|
||||
roots = 10
|
||||
}
|
||||
} else if _, err := git.GitBranchHead(pkg, "pool/factory"); err == nil {
|
||||
items := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "pool/factory", "--max-parents=0"))
|
||||
roots = len(common.SplitLines(items))
|
||||
} else {
|
||||
common.LogInfo("No factory import ...")
|
||||
}
|
||||
|
||||
for i := 0; i < len(develProjectPackages); i++ {
|
||||
pkg := develProjectPackages[i]
|
||||
meta, _ := obs.GetPackageMeta(prj, pkg)
|
||||
if len(meta.ScmSync) > 0 {
|
||||
if err2 := cloneDevel(git, "", pkg, meta.ScmSync); err2 != nil {
|
||||
log.Panicln(err2)
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main")
|
||||
continue
|
||||
} else {
|
||||
common.PanicOnError(gitImporter(prj, pkg))
|
||||
if out, err := git.GitExecWithOutput(pkg, "show-ref", "--branches"); err != nil || len(common.SplitStringNoEmpty(out, "\n")) == 0 {
|
||||
log.Println(" *** no branches in package. removing")
|
||||
develProjectPackages = slices.Delete(develProjectPackages, i, i+1)
|
||||
i--
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// mark newer branch as main
|
||||
branch := "factory"
|
||||
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "rev-list", "^factory", "devel"), "\n")) > 0 {
|
||||
log.Println(" *** pool branch 'devel' ahead. Switching branches.")
|
||||
branch = "devel"
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main", branch)
|
||||
if roots != 1 {
|
||||
common.LogError("Expected 1 root in factory, but found", roots)
|
||||
common.LogError("Ignoring current import")
|
||||
common.PanicOnError(os.RemoveAll(path.Join(git.GetPath(), pkg)))
|
||||
retErr = fmt.Errorf("Invalid factory repo -- treating as devel project only")
|
||||
return
|
||||
}
|
||||
|
||||
slices.SortFunc(factoryRepos, func(a, b *models.Repository) int {
|
||||
if a.Name == b.Name {
|
||||
orgOrderNo := func(org string) int {
|
||||
switch org {
|
||||
case "pool":
|
||||
return 1
|
||||
}
|
||||
return 0 // current devel to clone
|
||||
}
|
||||
devel_project, err := devel_projects.GetDevelProject(pkg)
|
||||
common.LogDebug("Devel project:", devel_project, err)
|
||||
if err == common.DevelProjectNotFound {
|
||||
// assume it's this project, maybe removed from factory
|
||||
devel_project = prj
|
||||
}
|
||||
common.LogDebug("finding missing branches in", pkg, devel_project)
|
||||
findMissingDevelBranch(git, pkg, devel_project)
|
||||
return
|
||||
}
|
||||
|
||||
return orgOrderNo(a.Owner.UserName) - orgOrderNo(b.Owner.UserName)
|
||||
}
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
factoryRepos = slices.CompactFunc(factoryRepos, func(a, b *models.Repository) bool {
|
||||
return a.Name == b.Name
|
||||
})
|
||||
|
||||
for _, pkg := range factoryRepos {
|
||||
var repo *models.Repository
|
||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg.Name), r.DefaultAuthentication); err != nil {
|
||||
// update package
|
||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||
WithOwner(pkg.Owner.UserName).
|
||||
WithRepo(pkg.Name).
|
||||
WithBody(&models.CreateForkOption{
|
||||
Organization: org,
|
||||
}), r.DefaultAuthentication)
|
||||
if err != nil {
|
||||
log.Panicln("Error while trying to create fork from", pkg.Owner.UserName, pkg.Name, "to", org, ":", err)
|
||||
}
|
||||
|
||||
repo = fork.Payload
|
||||
} else {
|
||||
repo = repoData.Payload
|
||||
}
|
||||
// branchName := repo.DefaultBranch
|
||||
|
||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show"), "\n")
|
||||
if !slices.Contains(remotes, "devel") {
|
||||
git.GitExecOrPanic(pkg.Name, "remote", "add", "devel", repo.SSHURL)
|
||||
// git.GitExecOrPanic(pkg.Name, "fetch", "devel")
|
||||
}
|
||||
if slices.Contains(remotes, "origin") {
|
||||
git.GitExecOrPanic(pkg.Name, "lfs", "fetch", "--all")
|
||||
git.GitExecOrPanic(pkg.Name, "lfs", "push", "devel", "--all")
|
||||
}
|
||||
git.GitExecOrPanic(pkg.Name, "push", "devel", "main", "-f")
|
||||
// git.GitExecOrPanic(pkg.Name, "checkout", "-B", "main", "devel/main")
|
||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(repo.Name).WithBody(&models.EditRepoOption{
|
||||
DefaultBranch: "main",
|
||||
DefaultMergeStyle: "fast-forward-only",
|
||||
func SetRepoOptions(repo *models.Repository) {
|
||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(repo.Name).WithBody(
|
||||
&models.EditRepoOption{
|
||||
HasPullRequests: true,
|
||||
HasPackages: false,
|
||||
HasReleases: false,
|
||||
@@ -479,80 +286,222 @@ func importRepos(packages []string) {
|
||||
AllowSquash: false,
|
||||
AllowFastForwardOnly: true,
|
||||
AllowRebaseUpdate: false,
|
||||
AllowManualMerge: false,
|
||||
AllowManualMerge: true,
|
||||
AutodetectManualMerge: true,
|
||||
DefaultMergeStyle: "fast-forward-only",
|
||||
AllowRebase: false,
|
||||
DefaultAllowMaintainerEdit: true,
|
||||
}), r.DefaultAuthentication)
|
||||
DefaultBranch: "main",
|
||||
}),
|
||||
r.DefaultAuthentication,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln("Failed to adjust repository:", repo.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePoolFork(factoryRepo *models.Repository) *models.Repository {
|
||||
pkg := factoryRepo.Name
|
||||
log.Println("factory fork creator for develProjectPackage:", pkg)
|
||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication); err != nil {
|
||||
// update package
|
||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||
WithOwner("pool").
|
||||
WithRepo(factoryRepo.Name).
|
||||
WithBody(&models.CreateForkOption{
|
||||
Organization: org,
|
||||
}), r.DefaultAuthentication)
|
||||
if err != nil {
|
||||
log.Panicln("Error while trying to create fork from 'pool'", pkg, "to", org, ":", err)
|
||||
}
|
||||
|
||||
repo := fork.Payload
|
||||
return repo
|
||||
} else {
|
||||
return repoData.Payload
|
||||
}
|
||||
}
|
||||
|
||||
func CreateDevelOnlyPackage(pkg string) *models.Repository {
|
||||
log.Println("repo creator for develProjectPackage:", pkg)
|
||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication); err != nil {
|
||||
giteaPkg := giteaPackage(pkg)
|
||||
repoData, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
||||
&models.CreateRepoOption{
|
||||
ObjectFormatName: "sha256",
|
||||
AutoInit: false,
|
||||
Name: &giteaPkg,
|
||||
DefaultBranch: "main",
|
||||
}),
|
||||
r.DefaultAuthentication,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
|
||||
log.Panicln("Error creating new package repository:", pkg, err)
|
||||
}
|
||||
|
||||
repo := repoData.Payload
|
||||
return repo
|
||||
} else {
|
||||
return repoData.Payload
|
||||
}
|
||||
}
|
||||
|
||||
func PushRepository(factoryRepo, develRepo *models.Repository, pkg string) (repo *models.Repository) {
|
||||
// branchName := repo.DefaultBranch
|
||||
if factoryRepo != nil {
|
||||
repo = CreatePoolFork(factoryRepo)
|
||||
|
||||
/*
|
||||
devel
|
||||
for _, b := range branches {
|
||||
if len(b) > 12 && b[0:12] == "develorigin/" {
|
||||
b = b[12:]
|
||||
if b == "factory" || b == "devel" {
|
||||
git.GitExec(pkg, "push", "develorigin", "--delete", b)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
//branches := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "branch", "-r"), "\n")
|
||||
/* factory
|
||||
for _, b := range branches {
|
||||
if len(b) > 12 && b[0:12] == "develorigin/" {
|
||||
b = b[12:]
|
||||
if b == "factory" || b == "devel" {
|
||||
git.GitExec(pkg.Name, "push", "develorigin", "--delete", b)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
// git.GitExecOrPanic(pkg.ame, "checkout", "-B", "main", "devel/main")
|
||||
} else {
|
||||
repo = CreateDevelOnlyPackage(pkg)
|
||||
}
|
||||
|
||||
for _, pkg := range develProjectPackages {
|
||||
var repo *models.Repository
|
||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication); err != nil {
|
||||
_, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
||||
&models.CreateRepoOption{
|
||||
ObjectFormatName: "sha256",
|
||||
AutoInit: false,
|
||||
Name: &pkg,
|
||||
DefaultBranch: "main",
|
||||
}),
|
||||
r.DefaultAuthentication,
|
||||
)
|
||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n")
|
||||
if !slices.Contains(remotes, "develorigin") {
|
||||
git.GitExecOrPanic(pkg, "remote", "add", "develorigin", repo.SSHURL)
|
||||
// git.GitExecOrPanic(pkgName, "fetch", "devel")
|
||||
}
|
||||
if slices.Contains(remotes, "origin") {
|
||||
git.GitExecOrPanic(pkg, "lfs", "fetch", "--all")
|
||||
git.GitExecOrPanic(pkg, "lfs", "push", "develorigin", "--all")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Panicln("Error creating new package repository:", pkg, err)
|
||||
git.GitExecOrPanic(pkg, "push", "develorigin", "main", "-f")
|
||||
SetRepoOptions(repo)
|
||||
git.GitExec(pkg, "push", "develorigin", "--delete", "factory")
|
||||
git.GitExec(pkg, "push", "develorigin", "--delete", "devel")
|
||||
return repo
|
||||
}
|
||||
|
||||
func importDevelRepoAndCheckHistory(pkg string, meta *common.PackageMeta) *models.Repository {
|
||||
repo := CreateDevelOnlyPackage(pkg)
|
||||
|
||||
log.Println("setting main branch for devel package:", pkg)
|
||||
if meta == nil {
|
||||
log.Println(" **** pkg meta is nil? ****")
|
||||
} else if len(meta.ScmSync) > 0 {
|
||||
if _, err := os.Stat(path.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
||||
u, _ := url.Parse(meta.ScmSync)
|
||||
if err2 := cloneDevel(git, "", pkg, meta.ScmSync, "origin", true); err2 != nil {
|
||||
log.Panicln(err2)
|
||||
}
|
||||
|
||||
ret, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(
|
||||
&models.EditRepoOption{
|
||||
HasPullRequests: true,
|
||||
HasPackages: false,
|
||||
HasReleases: false,
|
||||
HasActions: false,
|
||||
AllowMerge: true,
|
||||
AllowRebaseMerge: false,
|
||||
AllowSquash: false,
|
||||
AllowFastForwardOnly: true,
|
||||
AllowRebaseUpdate: false,
|
||||
AllowManualMerge: false,
|
||||
DefaultMergeStyle: "fast-forward-only",
|
||||
AllowRebase: false,
|
||||
DefaultAllowMaintainerEdit: true,
|
||||
}),
|
||||
r.DefaultAuthentication,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln("Failed to adjust repository:", pkg, err)
|
||||
}
|
||||
repo = ret.Payload
|
||||
|
||||
} else {
|
||||
repo = repoData.Payload
|
||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main", u.Fragment)
|
||||
}
|
||||
common.LogDebug("skip check for scmsync")
|
||||
return repo
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
||||
cloneDevel(git, "", pkg, repo.SSHURL, "develorigin", false) // in case we have imported
|
||||
}
|
||||
|
||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n")
|
||||
if !slices.Contains(remotes, "devel") {
|
||||
git.GitExecOrPanic(pkg, "remote", "add", "devel", repo.SSHURL)
|
||||
}
|
||||
if slices.Contains(remotes, "origin") {
|
||||
git.GitExecOrPanic(pkg, "lfs", "fetch", "--all")
|
||||
git.GitExecOrPanic(pkg, "lfs", "push", "devel", "--all")
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "push", "devel", "main", "-f")
|
||||
var p, dp string
|
||||
factory_branch, fhe := git.GitBranchHead(pkg, "factory")
|
||||
if fhe == nil {
|
||||
p = strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "--max-parents=0", "--count", factory_branch))
|
||||
} else {
|
||||
common.LogError(fhe)
|
||||
}
|
||||
devel_branch, dhe := git.GitBranchHead(pkg, "devel")
|
||||
if dhe == nil {
|
||||
dp = strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "--max-parents=0", "--count", devel_branch))
|
||||
} else {
|
||||
common.LogError(dhe)
|
||||
}
|
||||
|
||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(&models.EditRepoOption{
|
||||
DefaultBranch: "main",
|
||||
DefaultMergeStyle: "fast-forward-only",
|
||||
}), r.DefaultAuthentication)
|
||||
// even if one parent for both, we need common ancestry, or we are comparing different things.
|
||||
mb, mb_err := git.GitExecWithOutput(pkg, "merge-base", factory_branch, devel_branch)
|
||||
mb = strings.TrimSpace(mb)
|
||||
|
||||
if p != "1" || dp != "1" || mb_err != nil || mb != factory_branch || mb != devel_branch {
|
||||
common.LogInfo("Bad export found ... clearing", p, dp)
|
||||
common.LogInfo(" merge branch:", mb, factory_branch, devel_branch, mb_err)
|
||||
common.PanicOnError(os.RemoveAll(path.Join(git.GetPath(), pkg)))
|
||||
}
|
||||
|
||||
if err := gitImporter("openSUSE:Factory", pkg); err != nil {
|
||||
common.PanicOnError(gitImporter(prj, pkg))
|
||||
}
|
||||
if p := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "--max-parents=0", "--count", "factory")); p != "1" {
|
||||
common.LogError("Failed to import package:", pkg)
|
||||
common.PanicOnError(fmt.Errorf("Expecting 1 root in after devel import, but have %s", p))
|
||||
}
|
||||
if out, err := git.GitExecWithOutput(pkg, "show-ref", "--branches"); err != nil || len(common.SplitStringNoEmpty(out, "\n")) == 0 {
|
||||
common.LogError(" *** no branches in package. removing")
|
||||
return repo
|
||||
}
|
||||
|
||||
// mark newer branch as main
|
||||
branch := "factory"
|
||||
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "rev-list", "^factory", "devel"), "\n")) > 0 {
|
||||
branch = "devel"
|
||||
}
|
||||
common.LogInfo("setting main to", branch)
|
||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main", branch)
|
||||
return repo
|
||||
}
|
||||
|
||||
func ObsToRepoName(obspkg string) string {
|
||||
return strings.ReplaceAll(obspkg, "+", "_")
|
||||
}
|
||||
|
||||
func importRepo(pkg string) (BrokenFactoryPackage, FailedImport bool) {
|
||||
BrokenFactoryPackage = false
|
||||
FailedImport = false
|
||||
|
||||
var develRepo, factoryRepo *models.Repository
|
||||
|
||||
src_pkg_name := strings.Split(pkg, ":")
|
||||
pkg = src_pkg_name[0]
|
||||
|
||||
meta, err := obs.GetPackageMeta(prj, pkg)
|
||||
if err != nil {
|
||||
meta, err = obs.GetPackageMeta(prj, pkg)
|
||||
if err != nil {
|
||||
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
|
||||
log.Println("Error fetching pkg meta for:", prj, pkg, err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
common.PanicOnError(err)
|
||||
}
|
||||
|
||||
factoryRepo, err = importFactoryRepoAndCheckHistory(pkg, meta)
|
||||
if factoryRepo != nil && err != nil {
|
||||
BrokenFactoryPackage = true
|
||||
}
|
||||
if factoryRepo == nil && forceNonPoolPackages {
|
||||
log.Println(" IGNORING and will create these as non-pool packages!")
|
||||
}
|
||||
|
||||
if factoryRepo == nil || BrokenFactoryPackage {
|
||||
develRepo = importDevelRepoAndCheckHistory(pkg, meta)
|
||||
}
|
||||
|
||||
PushRepository(factoryRepo, develRepo, pkg)
|
||||
return
|
||||
}
|
||||
|
||||
func syncOrgTeams(groupName string, origTeam []common.PersonRepoMeta) []string {
|
||||
@@ -643,7 +592,7 @@ func syncPackageCollaborators(pkg string, orig_uids []common.PersonRepoMeta) []s
|
||||
missing := []string{}
|
||||
uids := make([]common.PersonRepoMeta, len(orig_uids))
|
||||
copy(uids, orig_uids)
|
||||
collab, err := client.Repository.RepoListCollaborators(repository.NewRepoListCollaboratorsParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
||||
collab, err := client.Repository.RepoListCollaborators(repository.NewRepoListCollaboratorsParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication)
|
||||
if err != nil {
|
||||
if errors.Is(err, &repository.RepoListCollaboratorsNotFound{}) {
|
||||
return missing
|
||||
@@ -664,7 +613,7 @@ func syncPackageCollaborators(pkg string, orig_uids []common.PersonRepoMeta) []s
|
||||
log.Println("missing collabs for", pkg, ":", uids)
|
||||
}
|
||||
for _, u := range uids {
|
||||
_, err := client.Repository.RepoAddCollaborator(repository.NewRepoAddCollaboratorParams().WithOwner(org).WithRepo(pkg).WithBody(&models.AddCollaboratorOption{
|
||||
_, err := client.Repository.RepoAddCollaborator(repository.NewRepoAddCollaboratorParams().WithOwner(org).WithRepo(giteaPackage(pkg)).WithBody(&models.AddCollaboratorOption{
|
||||
Permission: "write",
|
||||
}).WithCollaborator(u.UserID), r.DefaultAuthentication)
|
||||
|
||||
@@ -695,7 +644,16 @@ func syncMaintainersToGitea(pkgs []string) {
|
||||
missingDevs := []string{}
|
||||
devs := []string{}
|
||||
|
||||
if len(prjMeta.ScmSync) > 0 {
|
||||
common.LogInfo("Project already in Git. Maintainers must have been already synced. Skipping...")
|
||||
return
|
||||
}
|
||||
|
||||
for _, group := range prjMeta.Groups {
|
||||
if group.GroupID == "factory-maintainers" {
|
||||
log.Println("Ignoring factory-maintainers")
|
||||
continue
|
||||
}
|
||||
teamMembers, err := obs.GetGroupMeta(group.GroupID)
|
||||
if err != nil {
|
||||
log.Panicln("failed to get group", err)
|
||||
@@ -791,23 +749,43 @@ func createPrjGit() {
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "add", "_config")
|
||||
}
|
||||
|
||||
file, err = os.Create(path.Join(git.GetPath(), common.DefaultGitPrj, "project.build"))
|
||||
file, err = os.Create(path.Join(git.GetPath(), common.DefaultGitPrj, "staging.config"))
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
file.Write([]byte(prj))
|
||||
file.WriteString("{\n // Reference build project\n \"ObsProject\": \"" + prj + "\",\n}\n")
|
||||
file.Close()
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "add", "project.build")
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "add", "staging.config")
|
||||
|
||||
if file, err = os.Create(path.Join(git.GetPath(), common.DefaultGitPrj, "workflow.config")); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
file.WriteString("{\n \"Workflows\": [\"direct\", \"pr\"],\n \"Organization\": \"" + org + "\",\n}\n")
|
||||
file.Close()
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "add", "workflow.config")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TrimMultibuildPackages(packages []string) []string {
|
||||
for i := 0; i < len(packages); {
|
||||
if strings.Contains(packages[i], ":") {
|
||||
packages = slices.Delete(packages, i, i+1)
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
return packages
|
||||
}
|
||||
|
||||
var client *apiclient.GiteaAPI
|
||||
var r *transport.Runtime
|
||||
var git common.Git
|
||||
var obs *common.ObsClient
|
||||
var prj, org string
|
||||
var forceBadPool bool
|
||||
var forceNonPoolPackages bool
|
||||
var devel_projects common.DevelProjects
|
||||
|
||||
func main() {
|
||||
if err := common.RequireGiteaSecretToken(); err != nil {
|
||||
@@ -824,6 +802,7 @@ func main() {
|
||||
flags.SetOutput(helpString)
|
||||
//workflowConfig := flag.String("config", "", "Repository and workflow definition file")
|
||||
giteaHost := flags.String("gitea", "src.opensuse.org", "Gitea instance")
|
||||
obsUrl := flags.String("obs-url", "https://api.opensuse.org", "OBS API Url")
|
||||
//rabbitUrl := flag.String("url", "amqps://rabbit.opensuse.org", "URL for RabbitMQ instance")
|
||||
flags.BoolVar(&DebugMode, "debug", false, "Extra debugging information")
|
||||
// revNew := flag.Int("nrevs", 20, "Number of new revisions in factory branch. Indicator of broken history import")
|
||||
@@ -832,46 +811,81 @@ func main() {
|
||||
getMaintainers := flags.Bool("maintainers-only", false, "Get maintainers only and exit")
|
||||
syncMaintainers := flags.Bool("sync-maintainers-only", false, "Sync maintainers to Gitea and exit")
|
||||
flags.BoolVar(&forceBadPool, "bad-pool", false, "Force packages if pool has no branches due to bad import")
|
||||
flags.BoolVar(&forceNonPoolPackages, "non-pool", false, "Allow packages that are not in pool to be created. WARNING: Can't add to factory later!")
|
||||
specificPackages := flags.String("packages", "", "Process specific package, separated by commas, ignoring the others")
|
||||
resumeAt := flags.String("resume", "", "Resume import at given pacakge")
|
||||
syncPool := flags.Bool("sync-pool-only", false, "Force updates pool based on currrently imported project")
|
||||
|
||||
if help := flags.Parse(os.Args[1:]); help == flag.ErrHelp || flags.NArg() != 2 {
|
||||
printHelp(helpString.String())
|
||||
return
|
||||
}
|
||||
|
||||
if DebugMode {
|
||||
common.SetLoggingLevel(common.LogLevelDebug)
|
||||
}
|
||||
|
||||
r = transport.New(*giteaHost, apiclient.DefaultBasePath, [](string){"https"})
|
||||
r.DefaultAuthentication = transport.BearerToken(common.GetGiteaToken())
|
||||
// r.SetDebug(true)
|
||||
client = apiclient.New(r, nil)
|
||||
|
||||
obs, _ = common.NewObsClient("api.opensuse.org")
|
||||
obs, _ = common.NewObsClient(*obsUrl)
|
||||
|
||||
gh := common.GitHandlerGeneratorImpl{}
|
||||
var gh common.GitHandlerGenerator
|
||||
var err error
|
||||
git, err = gh.CreateGitHandler("Autogits - Devel Importer", "not.exist", "devel-importer")
|
||||
|
||||
devel_projects, err = common.FetchDevelProjects()
|
||||
if err != nil {
|
||||
log.Panicln("Failed to allocate git handler. Err:", err)
|
||||
log.Panic("Cannot load devel projects:", err)
|
||||
}
|
||||
log.Println("# devel projects loaded:", len(devel_projects))
|
||||
|
||||
if DebugMode {
|
||||
if len(*debugGitPath) > 0 {
|
||||
git.Close()
|
||||
git, err = gh.ReadExistingPath("Autogits - Devel Importer", "not.exist", *debugGitPath)
|
||||
gh, err = common.AllocateGitWorkTree(*debugGitPath, "Autogits - Devel Importer", "not.exist")
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
log.Println(" - working directory:" + git.GetPath())
|
||||
} else {
|
||||
defer git.Close()
|
||||
dir, _ := os.MkdirTemp(os.TempDir(), "devel-importer")
|
||||
gh, err = common.AllocateGitWorkTree(dir, "Autogits - Devel Importer", "not.exist")
|
||||
if err != nil {
|
||||
log.Panicln("Failed to allocate git handler", err)
|
||||
}
|
||||
}
|
||||
|
||||
prj = flags.Arg(0)
|
||||
org = flags.Arg(1)
|
||||
packages, err := runObsCommand("ls", prj)
|
||||
for i := 0; i < len(packages); {
|
||||
if strings.Contains(packages[i], ":") {
|
||||
packages = slices.Delete(packages, i, i+1)
|
||||
} else {
|
||||
i++
|
||||
packages = TrimMultibuildPackages(packages)
|
||||
|
||||
git, err = gh.CreateGitHandler(org)
|
||||
if err != nil {
|
||||
log.Panicln("Cannot create git", err)
|
||||
}
|
||||
defer git.Close()
|
||||
log.Println(" - working directory:" + git.GetPath())
|
||||
|
||||
if *syncPool {
|
||||
factory_pkgs, err := runObsCommand("ls", "openSUSE:Factory")
|
||||
common.PanicOnError(err)
|
||||
common.LogInfo("Syncing pool only...")
|
||||
factory_pkgs = TrimMultibuildPackages(factory_pkgs)
|
||||
|
||||
for _, pkg := range packages {
|
||||
if !slices.Contains(factory_pkgs, pkg) {
|
||||
continue
|
||||
}
|
||||
|
||||
repo, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(ObsToRepoName(pkg)), r.DefaultAuthentication)
|
||||
common.PanicOnError(err)
|
||||
|
||||
if !slices.Contains(common.SplitLines(git.GitExecWithOutputOrPanic(pkg, "remote")), "pool") {
|
||||
git.GitExecOrPanic(pkg, "remote", "add", "pool", repo.Payload.SSHURL)
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "fetch", "pool")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,12 +929,42 @@ func main() {
|
||||
|
||||
if *purgeOnly {
|
||||
log.Println("Purging repositories...")
|
||||
for _, pkg := range packages {
|
||||
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
||||
pkgs := packages
|
||||
if len(*specificPackages) > 0 {
|
||||
pkgs = common.SplitStringNoEmpty(*specificPackages, ",")
|
||||
}
|
||||
for _, pkg := range pkgs {
|
||||
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication)
|
||||
}
|
||||
os.Exit(10)
|
||||
}
|
||||
|
||||
importRepos(packages)
|
||||
if len(*specificPackages) != 0 {
|
||||
packages = common.SplitStringNoEmpty(*specificPackages, ",")
|
||||
}
|
||||
slices.Sort(packages)
|
||||
|
||||
BrokenOBSPackage := []string{}
|
||||
FailedImport := []string{}
|
||||
for _, pkg := range packages {
|
||||
if len(*resumeAt) > 0 && strings.Compare(*resumeAt, pkg) > 0 {
|
||||
common.LogDebug(pkg, "skipped due to resuming at", *resumeAt)
|
||||
continue
|
||||
}
|
||||
|
||||
b, f := importRepo(pkg)
|
||||
if b {
|
||||
BrokenOBSPackage = append(BrokenOBSPackage, pkg)
|
||||
}
|
||||
if f {
|
||||
FailedImport = append(FailedImport, pkg)
|
||||
}
|
||||
}
|
||||
|
||||
syncMaintainersToGitea(packages)
|
||||
|
||||
common.LogError("Have broken pool packages:", len(BrokenOBSPackage))
|
||||
// common.LogError("Total pool packages:", len(factoryRepos))
|
||||
common.LogError("Failed to import:", strings.Join(FailedImport, ","))
|
||||
common.LogInfo("BROKEN Pool packages:", strings.Join(BrokenOBSPackage, "\n"))
|
||||
}
|
||||
|
||||
15
devel-importer/migrated_projects
Normal file
15
devel-importer/migrated_projects
Normal file
@@ -0,0 +1,15 @@
|
||||
Kernel:firmware
|
||||
Kernel:kdump
|
||||
devel:languages:clojure
|
||||
devel:languages:erlang
|
||||
devel:languages:erlang:Factory
|
||||
devel:languages:hare
|
||||
devel:languages:javascript
|
||||
devel:languages:lua
|
||||
network:dhcp
|
||||
network:im:whatsapp
|
||||
network:messaging:xmpp
|
||||
systemsmanagement:cockpit
|
||||
systemsmanagement:wbem
|
||||
X11:lxde
|
||||
|
||||
46
gitea_status_proxy/config.go
Normal file
46
gitea_status_proxy/config.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/tailscale/hujson"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ForgeEndpoint string `json:"forge_url"`
|
||||
Keys []string `json:"keys"`
|
||||
}
|
||||
|
||||
type contextKey string
|
||||
|
||||
const configKey contextKey = "config"
|
||||
|
||||
func ReadConfig(reader io.Reader) (*Config, error) {
|
||||
data, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading config data: %w", err)
|
||||
}
|
||||
config := Config{}
|
||||
data, err = hujson.Standardize(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse json: %w", err)
|
||||
}
|
||||
if err := json.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("error parsing json to api keys and target url: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func ReadConfigFile(filename string) (*Config, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot open config file for reading. err: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
return ReadConfig(file)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user