This commit is contained in:
Adam Majer 2024-08-24 16:46:57 +02:00
parent 3052a5da5d
commit 1eec851e16
3 changed files with 432 additions and 2 deletions

View File

@ -431,3 +431,411 @@ const repoCreateJSON = `{
} }
}` }`
const createBranchJSON = `{
"sha": "691c91e5240f24f5a75393caf8a78826b8a6f9f272ab4faef024102739f0060a",
"ref": "main",
"ref_type": "branch",
"repository": {
"id": 90992,
"owner": {
"id": 939,
"login": "importtest",
"login_name": "",
"source_id": 0,
"full_name": "",
"email": "importtest@noreply@src.opensuse.org",
"avatar_url": "https://src.opensuse.org/avatars/10dc780b6dc535d772efc579e47b5acd",
"html_url": "https://src.opensuse.org/importtest",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2024-03-07T13:35:42+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": "importtest"
},
"name": "nodejs-common",
"full_name": "importtest/nodejs-common",
"description": "",
"empty": false,
"private": false,
"fork": true,
"template": false,
"parent": {
"id": 90520,
"owner": {
"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"
},
"name": "nodejs-common",
"full_name": "autogits/nodejs-common",
"description": "",
"empty": false,
"private": false,
"fork": true,
"template": false,
"parent": null,
"mirror": false,
"size": 96,
"language": "",
"languages_url": "https://src.opensuse.org/api/v1/repos/autogits/nodejs-common/languages",
"html_url": "https://src.opensuse.org/autogits/nodejs-common",
"url": "https://src.opensuse.org/api/v1/repos/autogits/nodejs-common",
"link": "",
"ssh_url": "gitea@src.opensuse.org:autogits/nodejs-common.git",
"clone_url": "https://src.opensuse.org/autogits/nodejs-common.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 2,
"watchers_count": 2,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "factory",
"archived": false,
"created_at": "2024-07-01T13:29:03+02:00",
"updated_at": "2024-07-01T13:29:03+02:00",
"archived_at": "1970-01-01T01:00:00+01:00",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"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
},
"mirror": false,
"size": 111,
"language": "",
"languages_url": "https://src.opensuse.org/api/v1/repos/importtest/nodejs-common/languages",
"html_url": "https://src.opensuse.org/importtest/nodejs-common",
"url": "https://src.opensuse.org/api/v1/repos/importtest/nodejs-common",
"link": "",
"ssh_url": "gitea@src.opensuse.org:importtest/nodejs-common.git",
"clone_url": "https://src.opensuse.org/importtest/nodejs-common.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": "factory",
"archived": false,
"created_at": "2024-08-22T18:03:46+02:00",
"updated_at": "2024-08-22T18:13:15+02:00",
"archived_at": "1970-01-01T01:00:00+01:00",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"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
},
"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 createTagJSON=`{
"sha": "691c91e5240f24f5a75393caf8a78826b8a6f9f272ab4faef024102739f0060a",
"ref": "foobar",
"ref_type": "tag",
"repository": {
"id": 90992,
"owner": {
"id": 939,
"login": "importtest",
"login_name": "",
"source_id": 0,
"full_name": "",
"email": "importtest@noreply@src.opensuse.org",
"avatar_url": "https://src.opensuse.org/avatars/10dc780b6dc535d772efc579e47b5acd",
"html_url": "https://src.opensuse.org/importtest",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2024-03-07T13:35:42+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": "importtest"
},
"name": "nodejs-common",
"full_name": "importtest/nodejs-common",
"description": "",
"empty": false,
"private": false,
"fork": true,
"template": false,
"parent": {
"id": 90520,
"owner": {
"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"
},
"name": "nodejs-common",
"full_name": "autogits/nodejs-common",
"description": "",
"empty": false,
"private": false,
"fork": true,
"template": false,
"parent": null,
"mirror": false,
"size": 96,
"language": "",
"languages_url": "https://src.opensuse.org/api/v1/repos/autogits/nodejs-common/languages",
"html_url": "https://src.opensuse.org/autogits/nodejs-common",
"url": "https://src.opensuse.org/api/v1/repos/autogits/nodejs-common",
"link": "",
"ssh_url": "gitea@src.opensuse.org:autogits/nodejs-common.git",
"clone_url": "https://src.opensuse.org/autogits/nodejs-common.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 2,
"watchers_count": 2,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "factory",
"archived": false,
"created_at": "2024-07-01T13:29:03+02:00",
"updated_at": "2024-07-01T13:29:03+02:00",
"archived_at": "1970-01-01T01:00:00+01:00",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"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
},
"mirror": false,
"size": 111,
"language": "",
"languages_url": "https://src.opensuse.org/api/v1/repos/importtest/nodejs-common/languages",
"html_url": "https://src.opensuse.org/importtest/nodejs-common",
"url": "https://src.opensuse.org/api/v1/repos/importtest/nodejs-common",
"link": "",
"ssh_url": "gitea@src.opensuse.org:importtest/nodejs-common.git",
"clone_url": "https://src.opensuse.org/importtest/nodejs-common.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": "factory",
"archived": false,
"created_at": "2024-08-22T18:03:46+02:00",
"updated_at": "2024-08-24T14:27:02+02:00",
"archived_at": "1970-01-01T01:00:00+01:00",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"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
},
"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"
}
}`

View File

@ -32,6 +32,13 @@ func connectToRabbitMQ() {
go ConnectToExchangeForPublish(host, username, password) go ConnectToExchangeForPublish(host, username, password)
} }
var id int
func dumpUnhandledData(reqType string, data []byte) {
id++
os.WriteFile("/tmp/unhandled-json-" + reqType + "-" + fmt.Sprint(id) + ".json", data, 0600);
}
func main() { func main() {
var listenAddr string var listenAddr string
@ -61,7 +68,7 @@ func main() {
} }
return return
} }
// reqType := hdr[0] reqType := hdr[0]
data, err := io.ReadAll(req.Body) data, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
errorStr := fmt.Sprintf("error reading hook info: %v", err) errorStr := fmt.Sprintf("error reading hook info: %v", err)
@ -81,8 +88,23 @@ func main() {
res.WriteHeader(http.StatusBadRequest) res.WriteHeader(http.StatusBadRequest)
} }
// repo := common.Repository{}
switch reqType {
case "create", "delete":
create := common.CreateWebhook{}
if err = json.Unmarshal(data, &create); err != nil {
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
dumpUnhandledData(reqType, data)
}
}
// repo = create.Repository
}
// err = PublishMessage(repo.Owner.Username, reqType, data)
// write to file for review // write to file for review
os.WriteFile("test_data."+fmt.Sprint(connectionId), data, 0644) os.WriteFile("test_data."+fmt.Sprint(connectionId), data, 0644)
connectionId++
/* /*
err = PublishMessage(reqType, req.PathValue("Org"), data) err = PublishMessage(reqType, req.PathValue("Org"), data)

View File

@ -59,7 +59,7 @@ func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte)
return nil return nil
} }
func PublishMessage(giteaWebhookType, giteaOrg string, data []byte) error { func PublishMessage(giteaOrg, giteaWebhookType string, data []byte) error {
return PublicActionMessage(giteaOrg, giteaWebhookType, "", data) return PublicActionMessage(giteaOrg, giteaWebhookType, "", data)
} }