.
This commit is contained in:
commit
598ecbbd5a
20
bots-common/Makefile
Normal file
20
bots-common/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
all: build
|
||||
|
||||
api.json:
|
||||
curl -o api.json https://src.opensuse.org/swagger.v1.json
|
||||
|
||||
obs.api.json:
|
||||
curl -o obs.api.yaml https://api.opensuse.org/apidocs/OBS-v2.10.50.yaml
|
||||
|
||||
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
|
||||
|
||||
generate.go:
|
||||
go generate
|
||||
|
||||
api: gitea-generated/client/gitea_api_client.go
|
||||
|
||||
build: api
|
||||
go build
|
||||
|
25728
bots-common/api.json
Normal file
25728
bots-common/api.json
Normal file
File diff suppressed because it is too large
Load Diff
5
bots-common/cfg.yaml
Normal file
5
bots-common/cfg.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
package: client
|
||||
output: client.gen.go
|
||||
generate:
|
||||
models: true
|
||||
client: true
|
8
bots-common/consts.go
Normal file
8
bots-common/consts.go
Normal file
@ -0,0 +1,8 @@
|
||||
package common;
|
||||
|
||||
const (
|
||||
GiteaTokenEnv = "GITEA_TOKEN"
|
||||
DefaultGitPrj = "_ObsPrj"
|
||||
GiteaRequestHeader = "X-Gitea-Event-Type"
|
||||
)
|
||||
|
432
bots-common/conststring_test.go
Normal file
432
bots-common/conststring_test.go
Normal file
@ -0,0 +1,432 @@
|
||||
package common
|
||||
|
||||
const examplePushJSON = `{
|
||||
"ref": "refs/heads/main",
|
||||
"before": "9fe6b18fee74f49786c39e062ef02bcfb560a0be6eb7851b81954123e2d55629",
|
||||
"after": "7d0be2432c179873081b715b8d38a563b8469608e110205821ba6a894e63c616",
|
||||
"compare_url": "https://src.opensuse.org/autogits/_ObsPrj/compare/9fe6b18fee74f49786c39e062ef02bcfb560a0be6eb7851b81954123e2d55629...7d0be2432c179873081b715b8d38a563b8469608e110205821ba6a894e63c616",
|
||||
"commits": [
|
||||
{
|
||||
"id": "7d0be2432c179873081b715b8d38a563b8469608e110205821ba6a894e63c616",
|
||||
"message": "Automatic project inclusion\n",
|
||||
"url": "https://src.opensuse.org/autogits/_ObsPrj/commit/7d0be2432c179873081b715b8d38a563b8469608e110205821ba6a894e63c616",
|
||||
"author": {
|
||||
"name": "GiteaBot - AutoDevel",
|
||||
"email": "not-exist@src.opensuse.org",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "root",
|
||||
"email": "not-exist@src.opensuse.org",
|
||||
"username": ""
|
||||
},
|
||||
"verification": null,
|
||||
"timestamp": "2024-06-25T14:38:31Z",
|
||||
"added": [
|
||||
".gitmodules",
|
||||
"nodejs22"
|
||||
],
|
||||
"removed": [],
|
||||
"modified": []
|
||||
}
|
||||
],
|
||||
"total_commits": 1,
|
||||
"head_commit": {
|
||||
"id": "7d0be2432c179873081b715b8d38a563b8469608e110205821ba6a894e63c616",
|
||||
"message": "Automatic project inclusion\n",
|
||||
"url": "https://src.opensuse.org/autogits/_ObsPrj/commit/7d0be2432c179873081b715b8d38a563b8469608e110205821ba6a894e63c616",
|
||||
"author": {
|
||||
"name": "GiteaBot - AutoDevel",
|
||||
"email": "not-exist@src.opensuse.org",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "root",
|
||||
"email": "not-exist@src.opensuse.org",
|
||||
"username": ""
|
||||
},
|
||||
"verification": null,
|
||||
"timestamp": "2024-06-25T14:38:31Z",
|
||||
"added": [
|
||||
".gitmodules",
|
||||
"nodejs22"
|
||||
],
|
||||
"removed": [],
|
||||
"modified": []
|
||||
},
|
||||
"repository": {
|
||||
"id": 90487,
|
||||
"owner": {
|
||||
"id": 983,
|
||||
"login": "autogits",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "",
|
||||
"email": "",
|
||||
"avatar_url": "https://src.opensuse.org/avatars/80a61ef3a14c3c22f0b8b1885d1a75d4",
|
||||
"html_url": "https://src.opensuse.org/autogits",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2024-06-20T09:46:37+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "autogits"
|
||||
},
|
||||
"name": "_ObsPrj",
|
||||
"full_name": "autogits/_ObsPrj",
|
||||
"description": "",
|
||||
"empty": false,
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"template": false,
|
||||
"parent": null,
|
||||
"mirror": false,
|
||||
"size": 27,
|
||||
"language": "",
|
||||
"languages_url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj/languages",
|
||||
"html_url": "https://src.opensuse.org/autogits/_ObsPrj",
|
||||
"url": "https://src.opensuse.org/api/v1/repos/autogits/_ObsPrj",
|
||||
"link": "",
|
||||
"ssh_url": "gitea@src.opensuse.org:autogits/_ObsPrj.git",
|
||||
"clone_url": "https://src.opensuse.org/autogits/_ObsPrj.git",
|
||||
"original_url": "",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"open_pr_counter": 0,
|
||||
"release_counter": 0,
|
||||
"default_branch": "main",
|
||||
"archived": false,
|
||||
"created_at": "2024-06-25T13:52:03+02:00",
|
||||
"updated_at": "2024-06-25T16:20:44+02:00",
|
||||
"archived_at": "1970-01-01T01:00:00+01:00",
|
||||
"permissions": {
|
||||
"admin": true,
|
||||
"push": true,
|
||||
"pull": true
|
||||
},
|
||||
"has_issues": true,
|
||||
"internal_tracker": {
|
||||
"enable_time_tracker": false,
|
||||
"allow_only_contributors_to_track_time": true,
|
||||
"enable_issue_dependencies": true
|
||||
},
|
||||
"has_wiki": true,
|
||||
"has_pull_requests": true,
|
||||
"has_projects": true,
|
||||
"projects_mode": "all",
|
||||
"has_releases": true,
|
||||
"has_packages": true,
|
||||
"has_actions": true,
|
||||
"ignore_whitespace_conflicts": false,
|
||||
"allow_merge_commits": true,
|
||||
"allow_rebase": true,
|
||||
"allow_rebase_explicit": true,
|
||||
"allow_squash_merge": true,
|
||||
"allow_fast_forward_only_merge": true,
|
||||
"allow_rebase_update": true,
|
||||
"default_delete_branch_after_merge": false,
|
||||
"default_merge_style": "merge",
|
||||
"default_allow_maintainer_edit": false,
|
||||
"avatar_url": "https://src.opensuse.org/",
|
||||
"internal": false,
|
||||
"mirror_interval": "",
|
||||
"object_format_name": "sha256",
|
||||
"mirror_updated": "0001-01-01T00:00:00Z",
|
||||
"repo_transfer": null
|
||||
},
|
||||
"pusher": {
|
||||
"id": 129,
|
||||
"login": "adamm",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "Adam Majer",
|
||||
"email": "adamm@noreply@src.opensuse.org",
|
||||
"avatar_url": "https://src.opensuse.org/avatar/babb6ae054a709c238a4e9b0f2b53d53",
|
||||
"html_url": "https://src.opensuse.org/adamm",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2023-07-21T16:43:48+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "adamm"
|
||||
},
|
||||
"sender": {
|
||||
"id": 129,
|
||||
"login": "adamm",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "Adam Majer",
|
||||
"email": "adamm@noreply@src.opensuse.org",
|
||||
"avatar_url": "https://src.opensuse.org/avatar/babb6ae054a709c238a4e9b0f2b53d53",
|
||||
"html_url": "https://src.opensuse.org/adamm",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2023-07-21T16:43:48+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "adamm"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const repoCreateJSON = `{
|
||||
"action": "created",
|
||||
"repository": {
|
||||
"id": 87483,
|
||||
"owner": {
|
||||
"id": 983,
|
||||
"login": "autogits",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "",
|
||||
"email": "",
|
||||
"avatar_url": "https://src.opensuse.org/avatars/80a61ef3a14c3c22f0b8b1885d1a75d4",
|
||||
"html_url": "https://src.opensuse.org/autogits",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2024-06-20T09:46:37+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "autogits"
|
||||
},
|
||||
"name": "nodejs22",
|
||||
"full_name": "autogits/nodejs22",
|
||||
"description": "",
|
||||
"empty": false,
|
||||
"private": false,
|
||||
"fork": true,
|
||||
"template": false,
|
||||
"parent": {
|
||||
"id": 54598,
|
||||
"owner": {
|
||||
"id": 64,
|
||||
"login": "pool",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "",
|
||||
"email": "",
|
||||
"avatar_url": "https://src.opensuse.org/avatars/b10a8c0bede9eb4ea771b04db3149f28",
|
||||
"html_url": "https://src.opensuse.org/pool",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2023-03-01T14:41:17+01:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "pool"
|
||||
},
|
||||
"name": "nodejs22",
|
||||
"full_name": "pool/nodejs22",
|
||||
"description": "",
|
||||
"empty": false,
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"template": false,
|
||||
"parent": null,
|
||||
"mirror": false,
|
||||
"size": 190,
|
||||
"language": "",
|
||||
"languages_url": "https://src.opensuse.org/api/v1/repos/pool/nodejs22/languages",
|
||||
"html_url": "https://src.opensuse.org/pool/nodejs22",
|
||||
"url": "https://src.opensuse.org/api/v1/repos/pool/nodejs22",
|
||||
"link": "",
|
||||
"ssh_url": "gitea@src.opensuse.org:pool/nodejs22.git",
|
||||
"clone_url": "https://src.opensuse.org/pool/nodejs22.git",
|
||||
"original_url": "",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 3,
|
||||
"watchers_count": 4,
|
||||
"open_issues_count": 0,
|
||||
"open_pr_counter": 1,
|
||||
"release_counter": 0,
|
||||
"default_branch": "factory",
|
||||
"archived": false,
|
||||
"created_at": "2024-05-28T12:47:21+02:00",
|
||||
"updated_at": "2024-06-12T14:54:03+02:00",
|
||||
"archived_at": "1970-01-01T01:00:00+01:00",
|
||||
"permissions": {
|
||||
"admin": true,
|
||||
"push": true,
|
||||
"pull": true
|
||||
},
|
||||
"has_issues": true,
|
||||
"internal_tracker": {
|
||||
"enable_time_tracker": false,
|
||||
"allow_only_contributors_to_track_time": true,
|
||||
"enable_issue_dependencies": true
|
||||
},
|
||||
"has_wiki": true,
|
||||
"has_pull_requests": true,
|
||||
"has_projects": true,
|
||||
"projects_mode": "",
|
||||
"has_releases": true,
|
||||
"has_packages": true,
|
||||
"has_actions": false,
|
||||
"ignore_whitespace_conflicts": false,
|
||||
"allow_merge_commits": true,
|
||||
"allow_rebase": true,
|
||||
"allow_rebase_explicit": true,
|
||||
"allow_squash_merge": true,
|
||||
"allow_fast_forward_only_merge": false,
|
||||
"allow_rebase_update": true,
|
||||
"default_delete_branch_after_merge": false,
|
||||
"default_merge_style": "merge",
|
||||
"default_allow_maintainer_edit": false,
|
||||
"avatar_url": "https://src.opensuse.org/",
|
||||
"internal": false,
|
||||
"mirror_interval": "",
|
||||
"object_format_name": "sha256",
|
||||
"mirror_updated": "0001-01-01T00:00:00Z",
|
||||
"repo_transfer": null
|
||||
},
|
||||
"mirror": false,
|
||||
"size": 0,
|
||||
"language": "",
|
||||
"languages_url": "https://src.opensuse.org/api/v1/repos/autogits/nodejs22/languages",
|
||||
"html_url": "https://src.opensuse.org/autogits/nodejs22",
|
||||
"url": "https://src.opensuse.org/api/v1/repos/autogits/nodejs22",
|
||||
"link": "",
|
||||
"ssh_url": "gitea@src.opensuse.org:autogits/nodejs22.git",
|
||||
"clone_url": "https://src.opensuse.org/autogits/nodejs22.git",
|
||||
"original_url": "",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 0,
|
||||
"open_issues_count": 0,
|
||||
"open_pr_counter": 0,
|
||||
"release_counter": 0,
|
||||
"default_branch": "factory",
|
||||
"archived": false,
|
||||
"created_at": "2024-06-20T10:09:12+02:00",
|
||||
"updated_at": "2024-06-20T10:09:12+02:00",
|
||||
"archived_at": "1970-01-01T01:00:00+01:00",
|
||||
"permissions": {
|
||||
"admin": true,
|
||||
"push": true,
|
||||
"pull": true
|
||||
},
|
||||
"has_issues": false,
|
||||
"has_wiki": false,
|
||||
"has_pull_requests": true,
|
||||
"has_projects": false,
|
||||
"projects_mode": "all",
|
||||
"has_releases": false,
|
||||
"has_packages": false,
|
||||
"has_actions": false,
|
||||
"ignore_whitespace_conflicts": false,
|
||||
"allow_merge_commits": true,
|
||||
"allow_rebase": true,
|
||||
"allow_rebase_explicit": true,
|
||||
"allow_squash_merge": true,
|
||||
"allow_fast_forward_only_merge": true,
|
||||
"allow_rebase_update": true,
|
||||
"default_delete_branch_after_merge": false,
|
||||
"default_merge_style": "merge",
|
||||
"default_allow_maintainer_edit": false,
|
||||
"avatar_url": "https://src.opensuse.org/",
|
||||
"internal": false,
|
||||
"mirror_interval": "",
|
||||
"object_format_name": "sha256",
|
||||
"mirror_updated": "0001-01-01T00:00:00Z",
|
||||
"repo_transfer": null
|
||||
},
|
||||
"organization": {
|
||||
"id": 983,
|
||||
"login": "autogits",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "",
|
||||
"email": "autogits@noreply@src.opensuse.org",
|
||||
"avatar_url": "https://src.opensuse.org/avatars/80a61ef3a14c3c22f0b8b1885d1a75d4",
|
||||
"html_url": "https://src.opensuse.org/autogits",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2024-06-20T09:46:37+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "autogits"
|
||||
},
|
||||
"sender": {
|
||||
"id": 129,
|
||||
"login": "adamm",
|
||||
"login_name": "",
|
||||
"source_id": 0,
|
||||
"full_name": "Adam Majer",
|
||||
"email": "adamm@noreply@src.opensuse.org",
|
||||
"avatar_url": "https://src.opensuse.org/avatar/babb6ae054a709c238a4e9b0f2b53d53",
|
||||
"html_url": "https://src.opensuse.org/adamm",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2023-07-21T16:43:48+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "adamm"
|
||||
}
|
||||
}`
|
8
bots-common/devtest.sh
Executable file
8
bots-common/devtest.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
while true; do
|
||||
clear
|
||||
go test
|
||||
inotifywait -q -e modify -e create -e delete -r .
|
||||
done
|
||||
|
5
bots-common/generate.go
Normal file
5
bots-common/generate.go
Normal file
@ -0,0 +1,5 @@
|
||||
package common
|
||||
|
||||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml obs.api.yaml
|
||||
|
||||
|
204
bots-common/git_utils.go
Normal file
204
bots-common/git_utils.go
Normal file
@ -0,0 +1,204 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//func (h *RequestHandler) ProcessBranchList() []string {
|
||||
// if h.HasError() {
|
||||
// return make([]string, 0)
|
||||
// }
|
||||
//
|
||||
// trackedBranches, err := os.ReadFile(path.Join(h.GitPath, DefaultGitPrj, TrackedBranchesFile))
|
||||
// if err != nil {
|
||||
// if errors.Is(err, os.ErrNotExist) {
|
||||
// trackedBranches = []byte("factory")
|
||||
// } else {
|
||||
// h.LogError("file error reading '%s' file in repo", TrackedBranchesFile)
|
||||
// h.Error = err
|
||||
// return make([]string, 0)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return strings.Split(string(trackedBranches), "\n")
|
||||
//}
|
||||
|
||||
type GitReference struct {
|
||||
Branch string
|
||||
Id string
|
||||
}
|
||||
|
||||
type GitReferences struct {
|
||||
refs []GitReference
|
||||
}
|
||||
|
||||
func (refs *GitReferences) addReference(id, branch string) {
|
||||
for _, ref := range refs.refs {
|
||||
if ref.Id == id && ref.Branch == branch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
refs.refs = append(refs.refs, GitReference{Branch: branch, Id: id})
|
||||
}
|
||||
|
||||
func processRefs(gitDir string) ([]GitReference, error) {
|
||||
packedRefsPath := path.Join(gitDir, "packed-refs")
|
||||
stat, err := os.Stat(packedRefsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if stat.Size() > 10000 || stat.IsDir() {
|
||||
return nil, fmt.Errorf("Funny business with 'packed-refs' in '%s'", gitDir)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(packedRefsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var references GitReferences
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if len(line) < 1 || line[0] == '#' {
|
||||
continue
|
||||
}
|
||||
|
||||
splitLine := strings.Split(line, " ")
|
||||
if len(splitLine) != 2 {
|
||||
return nil, fmt.Errorf("Unexpected packaged-refs entry '%#v' in '%s'", splitLine, packedRefsPath)
|
||||
}
|
||||
id, ref := splitLine[0], splitLine[1]
|
||||
const remoteRefPrefix = "refs/remotes/origin/"
|
||||
if ref[0:len(remoteRefPrefix)] != remoteRefPrefix {
|
||||
continue
|
||||
}
|
||||
|
||||
references.addReference(id, ref[len(remoteRefPrefix):])
|
||||
}
|
||||
|
||||
return references.refs, nil
|
||||
}
|
||||
|
||||
func findGitDir(p string) (string, error) {
|
||||
gitFile := path.Join(p, ".git")
|
||||
stat, err := os.Stat(gitFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if stat.IsDir() {
|
||||
return path.Join(p, ".git"), nil
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(gitFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
refs := strings.Split(line, ":")
|
||||
if len(refs) != 2 {
|
||||
return "", fmt.Errorf("Unknown format of .git file: '%s'\n", line)
|
||||
}
|
||||
|
||||
if refs[0] != "gitdir" {
|
||||
return "", fmt.Errorf("Unknown header of .git file: '%s'\n", refs[0])
|
||||
}
|
||||
|
||||
return path.Join(p, strings.TrimSpace(refs[1])), nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("Can't find git subdirectory in '%s'", p)
|
||||
}
|
||||
|
||||
func (e *RequestHandler) GitBranchHead(gitDir, branchName string) (string, error) {
|
||||
if e.HasError() {
|
||||
return "", e.Error
|
||||
}
|
||||
|
||||
path, err := findGitDir(path.Join(e.GitPath, gitDir))
|
||||
if err != nil {
|
||||
e.LogError("Error identifying gitdir in `%s`: %#v", gitDir, err)
|
||||
e.Error = err
|
||||
}
|
||||
|
||||
refs, err := processRefs(path)
|
||||
if err != nil {
|
||||
e.LogError("Error finding branches (%s): %#v", branchName, err)
|
||||
e.Error = err
|
||||
return "", e.Error
|
||||
}
|
||||
|
||||
for _, ref := range refs {
|
||||
if ref.Branch == branchName {
|
||||
return ref.Id, nil
|
||||
}
|
||||
}
|
||||
|
||||
e.Error = fmt.Errorf("Can't find default remote branch: %s", branchName)
|
||||
e.LogError("%s", e.Error.Error())
|
||||
return "", e.Error
|
||||
}
|
||||
|
||||
type ExecStream interface {
|
||||
Close()
|
||||
HasError() bool
|
||||
GitExec(cwd string, param ...string) ExecStream
|
||||
}
|
||||
|
||||
func (e *RequestHandler) Close() {
|
||||
if e.GitPath == "" {
|
||||
return
|
||||
}
|
||||
|
||||
e.Error = os.RemoveAll(e.GitPath)
|
||||
e.GitPath = ""
|
||||
return
|
||||
}
|
||||
|
||||
func (e *RequestHandler) HasError() bool {
|
||||
return e.Error != nil
|
||||
}
|
||||
|
||||
type writeFunc func(data []byte) (int, error)
|
||||
|
||||
func (f writeFunc) Write(data []byte) (int, error) {
|
||||
return f(data)
|
||||
}
|
||||
|
||||
func (e *RequestHandler) GitExec(cwd string, params ...string) ExecStream {
|
||||
if e.Error != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
cmd := exec.Command("/usr/bin/git", params...)
|
||||
cmd.Env = []string{
|
||||
"GIT_CEILING_DIRECTORIES=" + e.GitPath,
|
||||
"GIT_CONFIG_GLOBAL=/dev/null",
|
||||
"GIT_AUTHOR_NAME=" + e.GitCommiter,
|
||||
"EMAIL=not@exist@src.opensuse.org",
|
||||
"GIT_LFS_SKIP_SMUDGE=1",
|
||||
"GIT_SSH_COMMAND=/usr/bin/ssh -o StrictHostKeyChecking=yes",
|
||||
}
|
||||
cmd.Dir = filepath.Join(e.GitPath, cwd)
|
||||
cmd.Stdout = writeFunc(func(data []byte) (int, error) {
|
||||
e.Logger.Log("%s", data)
|
||||
return len(data), nil
|
||||
})
|
||||
cmd.Stderr = writeFunc(func(data []byte) (int, error) {
|
||||
e.Logger.LogError("%s", data)
|
||||
return len(data), nil
|
||||
})
|
||||
cmd.Stdin = nil
|
||||
|
||||
e.Log("git execute: %#v", cmd.Args)
|
||||
e.Error = cmd.Run()
|
||||
|
||||
return e
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package activitypub
|
||||
|
||||
// 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"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// New creates a new activitypub API client.
|
||||
func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
|
||||
return &Client{transport: transport, formats: formats}
|
||||
}
|
||||
|
||||
// New creates a new activitypub API client with basic auth credentials.
|
||||
// It takes the following parameters:
|
||||
// - host: http host (github.com).
|
||||
// - basePath: any base path for the API client ("/v1", "/v3").
|
||||
// - scheme: http scheme ("http", "https").
|
||||
// - user: user for basic authentication header.
|
||||
// - password: password for basic authentication header.
|
||||
func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService {
|
||||
transport := httptransport.New(host, basePath, []string{scheme})
|
||||
transport.DefaultAuthentication = httptransport.BasicAuth(user, password)
|
||||
return &Client{transport: transport, formats: strfmt.Default}
|
||||
}
|
||||
|
||||
// New creates a new activitypub API client with a bearer token for authentication.
|
||||
// It takes the following parameters:
|
||||
// - host: http host (github.com).
|
||||
// - basePath: any base path for the API client ("/v1", "/v3").
|
||||
// - scheme: http scheme ("http", "https").
|
||||
// - bearerToken: bearer token for Bearer authentication header.
|
||||
func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService {
|
||||
transport := httptransport.New(host, basePath, []string{scheme})
|
||||
transport.DefaultAuthentication = httptransport.BearerToken(bearerToken)
|
||||
return &Client{transport: transport, formats: strfmt.Default}
|
||||
}
|
||||
|
||||
/*
|
||||
Client for activitypub API
|
||||
*/
|
||||
type Client struct {
|
||||
transport runtime.ClientTransport
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ClientOption may be used to customize the behavior of Client methods.
|
||||
type ClientOption func(*runtime.ClientOperation)
|
||||
|
||||
// This client is generated with a few options you might find useful for your swagger spec.
|
||||
//
|
||||
// Feel free to add you own set of options.
|
||||
|
||||
// WithContentType allows the client to force the Content-Type header
|
||||
// to negotiate a specific Consumer from the server.
|
||||
//
|
||||
// You may use this option to set arbitrary extensions to your MIME media type.
|
||||
func WithContentType(mime string) ClientOption {
|
||||
return func(r *runtime.ClientOperation) {
|
||||
r.ConsumesMediaTypes = []string{mime}
|
||||
}
|
||||
}
|
||||
|
||||
// WithContentTypeApplicationJSON sets the Content-Type header to "application/json".
|
||||
func WithContentTypeApplicationJSON(r *runtime.ClientOperation) {
|
||||
r.ConsumesMediaTypes = []string{"application/json"}
|
||||
}
|
||||
|
||||
// WithContentTypeTextPlain sets the Content-Type header to "text/plain".
|
||||
func WithContentTypeTextPlain(r *runtime.ClientOperation) {
|
||||
r.ConsumesMediaTypes = []string{"text/plain"}
|
||||
}
|
||||
|
||||
// ClientService is the interface for Client methods
|
||||
type ClientService interface {
|
||||
ActivitypubPerson(params *ActivitypubPersonParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ActivitypubPersonOK, error)
|
||||
|
||||
ActivitypubPersonInbox(params *ActivitypubPersonInboxParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ActivitypubPersonInboxNoContent, error)
|
||||
|
||||
SetTransport(transport runtime.ClientTransport)
|
||||
}
|
||||
|
||||
/*
|
||||
ActivitypubPerson returns the person actor for a user
|
||||
*/
|
||||
func (a *Client) ActivitypubPerson(params *ActivitypubPersonParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ActivitypubPersonOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewActivitypubPersonParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "activitypubPerson",
|
||||
Method: "GET",
|
||||
PathPattern: "/activitypub/user-id/{user-id}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &ActivitypubPersonReader{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.(*ActivitypubPersonOK)
|
||||
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 activitypubPerson: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
ActivitypubPersonInbox sends to the inbox
|
||||
*/
|
||||
func (a *Client) ActivitypubPersonInbox(params *ActivitypubPersonInboxParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ActivitypubPersonInboxNoContent, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewActivitypubPersonInboxParams()
|
||||
}
|
||||
op := &runtime.ClientOperation{
|
||||
ID: "activitypubPersonInbox",
|
||||
Method: "POST",
|
||||
PathPattern: "/activitypub/user-id/{user-id}/inbox",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json", "text/plain"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Params: params,
|
||||
Reader: &ActivitypubPersonInboxReader{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.(*ActivitypubPersonInboxNoContent)
|
||||
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 activitypubPersonInbox: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
// SetTransport changes the transport on the client
|
||||
func (a *Client) SetTransport(transport runtime.ClientTransport) {
|
||||
a.transport = transport
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package activitypub
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// NewActivitypubPersonInboxParams creates a new ActivitypubPersonInboxParams 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 NewActivitypubPersonInboxParams() *ActivitypubPersonInboxParams {
|
||||
return &ActivitypubPersonInboxParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonInboxParamsWithTimeout creates a new ActivitypubPersonInboxParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewActivitypubPersonInboxParamsWithTimeout(timeout time.Duration) *ActivitypubPersonInboxParams {
|
||||
return &ActivitypubPersonInboxParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonInboxParamsWithContext creates a new ActivitypubPersonInboxParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewActivitypubPersonInboxParamsWithContext(ctx context.Context) *ActivitypubPersonInboxParams {
|
||||
return &ActivitypubPersonInboxParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonInboxParamsWithHTTPClient creates a new ActivitypubPersonInboxParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewActivitypubPersonInboxParamsWithHTTPClient(client *http.Client) *ActivitypubPersonInboxParams {
|
||||
return &ActivitypubPersonInboxParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ActivitypubPersonInboxParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the activitypub person inbox operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type ActivitypubPersonInboxParams struct {
|
||||
|
||||
/* UserID.
|
||||
|
||||
user ID of the user
|
||||
*/
|
||||
UserID int64
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the activitypub person inbox params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *ActivitypubPersonInboxParams) WithDefaults() *ActivitypubPersonInboxParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the activitypub person inbox params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *ActivitypubPersonInboxParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) WithTimeout(timeout time.Duration) *ActivitypubPersonInboxParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) WithContext(ctx context.Context) *ActivitypubPersonInboxParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) WithHTTPClient(client *http.Client) *ActivitypubPersonInboxParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithUserID adds the userID to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) WithUserID(userID int64) *ActivitypubPersonInboxParams {
|
||||
o.SetUserID(userID)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetUserID adds the userId to the activitypub person inbox params
|
||||
func (o *ActivitypubPersonInboxParams) SetUserID(userID int64) {
|
||||
o.UserID = userID
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *ActivitypubPersonInboxParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param user-id
|
||||
if err := r.SetPathParam("user-id", swag.FormatInt64(o.UserID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package activitypub
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// ActivitypubPersonInboxReader is a Reader for the ActivitypubPersonInbox structure.
|
||||
type ActivitypubPersonInboxReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *ActivitypubPersonInboxReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 204:
|
||||
result := NewActivitypubPersonInboxNoContent()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[POST /activitypub/user-id/{user-id}/inbox] activitypubPersonInbox", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonInboxNoContent creates a ActivitypubPersonInboxNoContent with default headers values
|
||||
func NewActivitypubPersonInboxNoContent() *ActivitypubPersonInboxNoContent {
|
||||
return &ActivitypubPersonInboxNoContent{}
|
||||
}
|
||||
|
||||
/*
|
||||
ActivitypubPersonInboxNoContent describes a response with status code 204, with default header values.
|
||||
|
||||
APIEmpty is an empty response
|
||||
*/
|
||||
type ActivitypubPersonInboxNoContent struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this activitypub person inbox no content response has a 2xx status code
|
||||
func (o *ActivitypubPersonInboxNoContent) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this activitypub person inbox no content response has a 3xx status code
|
||||
func (o *ActivitypubPersonInboxNoContent) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this activitypub person inbox no content response has a 4xx status code
|
||||
func (o *ActivitypubPersonInboxNoContent) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this activitypub person inbox no content response has a 5xx status code
|
||||
func (o *ActivitypubPersonInboxNoContent) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this activitypub person inbox no content response a status code equal to that given
|
||||
func (o *ActivitypubPersonInboxNoContent) IsCode(code int) bool {
|
||||
return code == 204
|
||||
}
|
||||
|
||||
// Code gets the status code for the activitypub person inbox no content response
|
||||
func (o *ActivitypubPersonInboxNoContent) Code() int {
|
||||
return 204
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonInboxNoContent) Error() string {
|
||||
return fmt.Sprintf("[POST /activitypub/user-id/{user-id}/inbox][%d] activitypubPersonInboxNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonInboxNoContent) String() string {
|
||||
return fmt.Sprintf("[POST /activitypub/user-id/{user-id}/inbox][%d] activitypubPersonInboxNoContent", 204)
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonInboxNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package activitypub
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// NewActivitypubPersonParams creates a new ActivitypubPersonParams 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 NewActivitypubPersonParams() *ActivitypubPersonParams {
|
||||
return &ActivitypubPersonParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonParamsWithTimeout creates a new ActivitypubPersonParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewActivitypubPersonParamsWithTimeout(timeout time.Duration) *ActivitypubPersonParams {
|
||||
return &ActivitypubPersonParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonParamsWithContext creates a new ActivitypubPersonParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewActivitypubPersonParamsWithContext(ctx context.Context) *ActivitypubPersonParams {
|
||||
return &ActivitypubPersonParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonParamsWithHTTPClient creates a new ActivitypubPersonParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewActivitypubPersonParamsWithHTTPClient(client *http.Client) *ActivitypubPersonParams {
|
||||
return &ActivitypubPersonParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ActivitypubPersonParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the activitypub person operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type ActivitypubPersonParams struct {
|
||||
|
||||
/* UserID.
|
||||
|
||||
user ID of the user
|
||||
*/
|
||||
UserID int64
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the activitypub person params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *ActivitypubPersonParams) WithDefaults() *ActivitypubPersonParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the activitypub person params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *ActivitypubPersonParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) WithTimeout(timeout time.Duration) *ActivitypubPersonParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) WithContext(ctx context.Context) *ActivitypubPersonParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) WithHTTPClient(client *http.Client) *ActivitypubPersonParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithUserID adds the userID to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) WithUserID(userID int64) *ActivitypubPersonParams {
|
||||
o.SetUserID(userID)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetUserID adds the userId to the activitypub person params
|
||||
func (o *ActivitypubPersonParams) SetUserID(userID int64) {
|
||||
o.UserID = userID
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *ActivitypubPersonParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param user-id
|
||||
if err := r.SetPathParam("user-id", swag.FormatInt64(o.UserID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package activitypub
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// ActivitypubPersonReader is a Reader for the ActivitypubPerson structure.
|
||||
type ActivitypubPersonReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *ActivitypubPersonReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewActivitypubPersonOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
default:
|
||||
return nil, runtime.NewAPIError("[GET /activitypub/user-id/{user-id}] activitypubPerson", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewActivitypubPersonOK creates a ActivitypubPersonOK with default headers values
|
||||
func NewActivitypubPersonOK() *ActivitypubPersonOK {
|
||||
return &ActivitypubPersonOK{}
|
||||
}
|
||||
|
||||
/*
|
||||
ActivitypubPersonOK describes a response with status code 200, with default header values.
|
||||
|
||||
ActivityPub
|
||||
*/
|
||||
type ActivitypubPersonOK struct {
|
||||
Payload *models.ActivityPub
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this activitypub person o k response has a 2xx status code
|
||||
func (o *ActivitypubPersonOK) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this activitypub person o k response has a 3xx status code
|
||||
func (o *ActivitypubPersonOK) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this activitypub person o k response has a 4xx status code
|
||||
func (o *ActivitypubPersonOK) IsClientError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsServerError returns true when this activitypub person o k response has a 5xx status code
|
||||
func (o *ActivitypubPersonOK) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this activitypub person o k response a status code equal to that given
|
||||
func (o *ActivitypubPersonOK) IsCode(code int) bool {
|
||||
return code == 200
|
||||
}
|
||||
|
||||
// Code gets the status code for the activitypub person o k response
|
||||
func (o *ActivitypubPersonOK) Code() int {
|
||||
return 200
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonOK) Error() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /activitypub/user-id/{user-id}][%d] activitypubPersonOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonOK) String() string {
|
||||
payload, _ := json.Marshal(o.Payload)
|
||||
return fmt.Sprintf("[GET /activitypub/user-id/{user-id}][%d] activitypubPersonOK %s", 200, payload)
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonOK) GetPayload() *models.ActivityPub {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *ActivitypubPersonOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.ActivityPub)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package admin
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// NewAdminAddUserBadgesParams creates a new AdminAddUserBadgesParams 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 NewAdminAddUserBadgesParams() *AdminAddUserBadgesParams {
|
||||
return &AdminAddUserBadgesParams{
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAdminAddUserBadgesParamsWithTimeout creates a new AdminAddUserBadgesParams object
|
||||
// with the ability to set a timeout on a request.
|
||||
func NewAdminAddUserBadgesParamsWithTimeout(timeout time.Duration) *AdminAddUserBadgesParams {
|
||||
return &AdminAddUserBadgesParams{
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAdminAddUserBadgesParamsWithContext creates a new AdminAddUserBadgesParams object
|
||||
// with the ability to set a context for a request.
|
||||
func NewAdminAddUserBadgesParamsWithContext(ctx context.Context) *AdminAddUserBadgesParams {
|
||||
return &AdminAddUserBadgesParams{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAdminAddUserBadgesParamsWithHTTPClient creates a new AdminAddUserBadgesParams object
|
||||
// with the ability to set a custom HTTPClient for a request.
|
||||
func NewAdminAddUserBadgesParamsWithHTTPClient(client *http.Client) *AdminAddUserBadgesParams {
|
||||
return &AdminAddUserBadgesParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
AdminAddUserBadgesParams contains all the parameters to send to the API endpoint
|
||||
|
||||
for the admin add user badges operation.
|
||||
|
||||
Typically these are written to a http.Request.
|
||||
*/
|
||||
type AdminAddUserBadgesParams struct {
|
||||
|
||||
// Body.
|
||||
Body *models.UserBadgeOption
|
||||
|
||||
/* Username.
|
||||
|
||||
username of user
|
||||
*/
|
||||
Username string
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithDefaults hydrates default values in the admin add user badges params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *AdminAddUserBadgesParams) WithDefaults() *AdminAddUserBadgesParams {
|
||||
o.SetDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDefaults hydrates default values in the admin add user badges params (not the query body).
|
||||
//
|
||||
// All values with no default are reset to their zero value.
|
||||
func (o *AdminAddUserBadgesParams) SetDefaults() {
|
||||
// no default values defined for this parameter
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) WithTimeout(timeout time.Duration) *AdminAddUserBadgesParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) WithContext(ctx context.Context) *AdminAddUserBadgesParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) WithHTTPClient(client *http.Client) *AdminAddUserBadgesParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) WithBody(body *models.UserBadgeOption) *AdminAddUserBadgesParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) SetBody(body *models.UserBadgeOption) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithUsername adds the username to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) WithUsername(username string) *AdminAddUserBadgesParams {
|
||||
o.SetUsername(username)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetUsername adds the username to the admin add user badges params
|
||||
func (o *AdminAddUserBadgesParams) SetUsername(username string) {
|
||||
o.Username = username
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *AdminAddUserBadgesParams) 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 username
|
||||