-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e3cded
commit 0af48bd
Showing
6 changed files
with
385 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::collections::HashMap; | ||
|
||
use axum::http::{HeaderMap, StatusCode}; | ||
use axum::body::Bytes; | ||
|
||
use crate::web::discord; | ||
use crate::web::event::{EventConfig, read_config, select_template, expand_template}; | ||
use crate::web::event::Event; | ||
|
||
use super::github_filter::github_request_is_authentic; | ||
|
||
pub const X_GTIHUB_EVENT: &str = "fork"; | ||
|
||
pub struct GithubForked | ||
{ | ||
config: EventConfig | ||
} | ||
|
||
impl GithubForked | ||
{ | ||
pub fn new() -> GithubForked | ||
{ | ||
GithubForked { config: EventConfig::new() } | ||
} | ||
} | ||
|
||
impl Event for GithubForked | ||
{ | ||
fn get_token(&self) -> String | ||
{ | ||
self.config.get_token() | ||
} | ||
|
||
fn get_end_point(&self) -> discord::request::model::Webhook | ||
{ | ||
self.config.get_end_point() | ||
} | ||
|
||
fn load_config(&mut self) | ||
{ | ||
self.config = read_config("github_forked"); | ||
} | ||
|
||
fn is_authentic(&self, headers: HeaderMap, body: Bytes) -> StatusCode | ||
{ | ||
return github_request_is_authentic(self.get_token(), headers, body); | ||
} | ||
|
||
fn into_response(&self, data: HashMap<String, serde_json::Value>) -> (Option<String>, StatusCode) | ||
{ | ||
|
||
let template = select_template(self.config.get_templates(), data.clone()); | ||
|
||
let template = if data["repository"]["name"].is_string() | ||
{ | ||
match data["repository"]["name"] == "Pulse" | ||
{ | ||
true => template.replacen("<repository/name>", "Pulse (that's me!)", 1), | ||
false => {template} | ||
} | ||
} | ||
else | ||
{ | ||
return (None, StatusCode::INTERNAL_SERVER_ERROR) | ||
}; | ||
|
||
crate::debug(format!("Fork from {:?}", data["sender"]["login"]), None); | ||
|
||
if self.config.silent_on_private_repos() && data["repository"]["private"].as_bool().is_some_and(|x|x) | ||
{ | ||
return (None, StatusCode::OK); | ||
} | ||
|
||
(expand_template(template, data), StatusCode::OK) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -995,4 +995,264 @@ pub const STAR_DELETED_PAYLOAD: &str = r#" | |
"site_admin": false | ||
} | ||
} | ||
"#; | ||
"#; | ||
|
||
pub const FORKED_PAYLOAD: &str = r#" | ||
{ | ||
"forkee": { | ||
"id": 752584241, | ||
"node_id": "R_kgDOLNuGMQ", | ||
"name": "Pulse", | ||
"full_name": "Jerboa-app/Pulse", | ||
"private": false, | ||
"owner": { | ||
"login": "Jerboa-app", | ||
"id": 84378622, | ||
"node_id": "MDQ6VXNlcjg0Mzc4NjIy", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/84378622?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/Jerboa-app", | ||
"html_url": "https://github.com/Jerboa-app", | ||
"followers_url": "https://api.github.com/users/Jerboa-app/followers", | ||
"following_url": "https://api.github.com/users/Jerboa-app/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/Jerboa-app/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/Jerboa-app/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/Jerboa-app/subscriptions", | ||
"organizations_url": "https://api.github.com/users/Jerboa-app/orgs", | ||
"repos_url": "https://api.github.com/users/Jerboa-app/repos", | ||
"events_url": "https://api.github.com/users/Jerboa-app/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/Jerboa-app/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"html_url": "https://github.com/Jerboa-app/Pulse", | ||
"description": "Discord webhook bot posting messages on Github events | hot-loadable formatting templates; string interpolation in templates for arbitrary JSON bodies", | ||
"fork": true, | ||
"url": "https://api.github.com/repos/Jerboa-app/Pulse", | ||
"forks_url": "https://api.github.com/repos/Jerboa-app/Pulse/forks", | ||
"keys_url": "https://api.github.com/repos/Jerboa-app/Pulse/keys{/key_id}", | ||
"collaborators_url": "https://api.github.com/repos/Jerboa-app/Pulse/collaborators{/collaborator}", | ||
"teams_url": "https://api.github.com/repos/Jerboa-app/Pulse/teams", | ||
"hooks_url": "https://api.github.com/repos/Jerboa-app/Pulse/hooks", | ||
"issue_events_url": "https://api.github.com/repos/Jerboa-app/Pulse/issues/events{/number}", | ||
"events_url": "https://api.github.com/repos/Jerboa-app/Pulse/events", | ||
"assignees_url": "https://api.github.com/repos/Jerboa-app/Pulse/assignees{/user}", | ||
"branches_url": "https://api.github.com/repos/Jerboa-app/Pulse/branches{/branch}", | ||
"tags_url": "https://api.github.com/repos/Jerboa-app/Pulse/tags", | ||
"blobs_url": "https://api.github.com/repos/Jerboa-app/Pulse/git/blobs{/sha}", | ||
"git_tags_url": "https://api.github.com/repos/Jerboa-app/Pulse/git/tags{/sha}", | ||
"git_refs_url": "https://api.github.com/repos/Jerboa-app/Pulse/git/refs{/sha}", | ||
"trees_url": "https://api.github.com/repos/Jerboa-app/Pulse/git/trees{/sha}", | ||
"statuses_url": "https://api.github.com/repos/Jerboa-app/Pulse/statuses/{sha}", | ||
"languages_url": "https://api.github.com/repos/Jerboa-app/Pulse/languages", | ||
"stargazers_url": "https://api.github.com/repos/Jerboa-app/Pulse/stargazers", | ||
"contributors_url": "https://api.github.com/repos/Jerboa-app/Pulse/contributors", | ||
"subscribers_url": "https://api.github.com/repos/Jerboa-app/Pulse/subscribers", | ||
"subscription_url": "https://api.github.com/repos/Jerboa-app/Pulse/subscription", | ||
"commits_url": "https://api.github.com/repos/Jerboa-app/Pulse/commits{/sha}", | ||
"git_commits_url": "https://api.github.com/repos/Jerboa-app/Pulse/git/commits{/sha}", | ||
"comments_url": "https://api.github.com/repos/Jerboa-app/Pulse/comments{/number}", | ||
"issue_comment_url": "https://api.github.com/repos/Jerboa-app/Pulse/issues/comments{/number}", | ||
"contents_url": "https://api.github.com/repos/Jerboa-app/Pulse/contents/{+path}", | ||
"compare_url": "https://api.github.com/repos/Jerboa-app/Pulse/compare/{base}...{head}", | ||
"merges_url": "https://api.github.com/repos/Jerboa-app/Pulse/merges", | ||
"archive_url": "https://api.github.com/repos/Jerboa-app/Pulse/{archive_format}{/ref}", | ||
"downloads_url": "https://api.github.com/repos/Jerboa-app/Pulse/downloads", | ||
"issues_url": "https://api.github.com/repos/Jerboa-app/Pulse/issues{/number}", | ||
"pulls_url": "https://api.github.com/repos/Jerboa-app/Pulse/pulls{/number}", | ||
"milestones_url": "https://api.github.com/repos/Jerboa-app/Pulse/milestones{/number}", | ||
"notifications_url": "https://api.github.com/repos/Jerboa-app/Pulse/notifications{?since,all,participating}", | ||
"labels_url": "https://api.github.com/repos/Jerboa-app/Pulse/labels{/name}", | ||
"releases_url": "https://api.github.com/repos/Jerboa-app/Pulse/releases{/id}", | ||
"deployments_url": "https://api.github.com/repos/Jerboa-app/Pulse/deployments", | ||
"created_at": "2024-02-04T09:21:49Z", | ||
"updated_at": "2024-02-04T09:21:50Z", | ||
"pushed_at": "2024-01-26T11:20:24Z", | ||
"git_url": "git://github.com/Jerboa-app/Pulse.git", | ||
"ssh_url": "[email protected]:Jerboa-app/Pulse.git", | ||
"clone_url": "https://github.com/Jerboa-app/Pulse.git", | ||
"svn_url": "https://github.com/Jerboa-app/Pulse", | ||
"homepage": "", | ||
"size": 102, | ||
"stargazers_count": 0, | ||
"watchers_count": 0, | ||
"language": null, | ||
"has_issues": false, | ||
"has_projects": true, | ||
"has_downloads": true, | ||
"has_wiki": false, | ||
"has_pages": false, | ||
"has_discussions": false, | ||
"forks_count": 0, | ||
"mirror_url": null, | ||
"archived": false, | ||
"disabled": false, | ||
"open_issues_count": 0, | ||
"license": null, | ||
"allow_forking": true, | ||
"is_template": false, | ||
"web_commit_signoff_required": false, | ||
"topics": [ | ||
], | ||
"visibility": "public", | ||
"forks": 0, | ||
"open_issues": 0, | ||
"watchers": 0, | ||
"default_branch": "main", | ||
"public": true | ||
}, | ||
"repository": { | ||
"id": 738663171, | ||
"node_id": "R_kgDOLAcbAw", | ||
"name": "Pulse", | ||
"full_name": "JerboaBurrow/Pulse", | ||
"private": false, | ||
"owner": { | ||
"login": "JerboaBurrow", | ||
"id": 109722648, | ||
"node_id": "O_kgDOBoo8GA", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/109722648?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/JerboaBurrow", | ||
"html_url": "https://github.com/JerboaBurrow", | ||
"followers_url": "https://api.github.com/users/JerboaBurrow/followers", | ||
"following_url": "https://api.github.com/users/JerboaBurrow/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/JerboaBurrow/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/JerboaBurrow/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/JerboaBurrow/subscriptions", | ||
"organizations_url": "https://api.github.com/users/JerboaBurrow/orgs", | ||
"repos_url": "https://api.github.com/users/JerboaBurrow/repos", | ||
"events_url": "https://api.github.com/users/JerboaBurrow/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/JerboaBurrow/received_events", | ||
"type": "Organization", | ||
"site_admin": false | ||
}, | ||
"html_url": "https://github.com/JerboaBurrow/Pulse", | ||
"description": "Discord webhook bot posting messages on Github events | hot-loadable formatting templates; string interpolation in templates for arbitrary JSON bodies", | ||
"fork": false, | ||
"url": "https://api.github.com/repos/JerboaBurrow/Pulse", | ||
"forks_url": "https://api.github.com/repos/JerboaBurrow/Pulse/forks", | ||
"keys_url": "https://api.github.com/repos/JerboaBurrow/Pulse/keys{/key_id}", | ||
"collaborators_url": "https://api.github.com/repos/JerboaBurrow/Pulse/collaborators{/collaborator}", | ||
"teams_url": "https://api.github.com/repos/JerboaBurrow/Pulse/teams", | ||
"hooks_url": "https://api.github.com/repos/JerboaBurrow/Pulse/hooks", | ||
"issue_events_url": "https://api.github.com/repos/JerboaBurrow/Pulse/issues/events{/number}", | ||
"events_url": "https://api.github.com/repos/JerboaBurrow/Pulse/events", | ||
"assignees_url": "https://api.github.com/repos/JerboaBurrow/Pulse/assignees{/user}", | ||
"branches_url": "https://api.github.com/repos/JerboaBurrow/Pulse/branches{/branch}", | ||
"tags_url": "https://api.github.com/repos/JerboaBurrow/Pulse/tags", | ||
"blobs_url": "https://api.github.com/repos/JerboaBurrow/Pulse/git/blobs{/sha}", | ||
"git_tags_url": "https://api.github.com/repos/JerboaBurrow/Pulse/git/tags{/sha}", | ||
"git_refs_url": "https://api.github.com/repos/JerboaBurrow/Pulse/git/refs{/sha}", | ||
"trees_url": "https://api.github.com/repos/JerboaBurrow/Pulse/git/trees{/sha}", | ||
"statuses_url": "https://api.github.com/repos/JerboaBurrow/Pulse/statuses/{sha}", | ||
"languages_url": "https://api.github.com/repos/JerboaBurrow/Pulse/languages", | ||
"stargazers_url": "https://api.github.com/repos/JerboaBurrow/Pulse/stargazers", | ||
"contributors_url": "https://api.github.com/repos/JerboaBurrow/Pulse/contributors", | ||
"subscribers_url": "https://api.github.com/repos/JerboaBurrow/Pulse/subscribers", | ||
"subscription_url": "https://api.github.com/repos/JerboaBurrow/Pulse/subscription", | ||
"commits_url": "https://api.github.com/repos/JerboaBurrow/Pulse/commits{/sha}", | ||
"git_commits_url": "https://api.github.com/repos/JerboaBurrow/Pulse/git/commits{/sha}", | ||
"comments_url": "https://api.github.com/repos/JerboaBurrow/Pulse/comments{/number}", | ||
"issue_comment_url": "https://api.github.com/repos/JerboaBurrow/Pulse/issues/comments{/number}", | ||
"contents_url": "https://api.github.com/repos/JerboaBurrow/Pulse/contents/{+path}", | ||
"compare_url": "https://api.github.com/repos/JerboaBurrow/Pulse/compare/{base}...{head}", | ||
"merges_url": "https://api.github.com/repos/JerboaBurrow/Pulse/merges", | ||
"archive_url": "https://api.github.com/repos/JerboaBurrow/Pulse/{archive_format}{/ref}", | ||
"downloads_url": "https://api.github.com/repos/JerboaBurrow/Pulse/downloads", | ||
"issues_url": "https://api.github.com/repos/JerboaBurrow/Pulse/issues{/number}", | ||
"pulls_url": "https://api.github.com/repos/JerboaBurrow/Pulse/pulls{/number}", | ||
"milestones_url": "https://api.github.com/repos/JerboaBurrow/Pulse/milestones{/number}", | ||
"notifications_url": "https://api.github.com/repos/JerboaBurrow/Pulse/notifications{?since,all,participating}", | ||
"labels_url": "https://api.github.com/repos/JerboaBurrow/Pulse/labels{/name}", | ||
"releases_url": "https://api.github.com/repos/JerboaBurrow/Pulse/releases{/id}", | ||
"deployments_url": "https://api.github.com/repos/JerboaBurrow/Pulse/deployments", | ||
"created_at": "2024-01-03T18:47:03Z", | ||
"updated_at": "2024-01-18T14:21:05Z", | ||
"pushed_at": "2024-01-26T11:20:24Z", | ||
"git_url": "git://github.com/JerboaBurrow/Pulse.git", | ||
"ssh_url": "[email protected]:JerboaBurrow/Pulse.git", | ||
"clone_url": "https://github.com/JerboaBurrow/Pulse.git", | ||
"svn_url": "https://github.com/JerboaBurrow/Pulse", | ||
"homepage": "", | ||
"size": 102, | ||
"stargazers_count": 0, | ||
"watchers_count": 0, | ||
"language": "Rust", | ||
"has_issues": true, | ||
"has_projects": true, | ||
"has_downloads": true, | ||
"has_wiki": false, | ||
"has_pages": false, | ||
"has_discussions": false, | ||
"forks_count": 1, | ||
"mirror_url": null, | ||
"archived": false, | ||
"disabled": false, | ||
"open_issues_count": 3, | ||
"license": { | ||
"key": "mit", | ||
"name": "MIT License", | ||
"spdx_id": "MIT", | ||
"url": "https://api.github.com/licenses/mit", | ||
"node_id": "MDc6TGljZW5zZTEz" | ||
}, | ||
"allow_forking": true, | ||
"is_template": false, | ||
"web_commit_signoff_required": false, | ||
"topics": [ | ||
"bot", | ||
"discord", | ||
"github", | ||
"http", | ||
"https", | ||
"rust", | ||
"server", | ||
"webdev", | ||
"webhook" | ||
], | ||
"visibility": "public", | ||
"forks": 1, | ||
"open_issues": 3, | ||
"watchers": 0, | ||
"default_branch": "main", | ||
"custom_properties": { | ||
} | ||
}, | ||
"organization": { | ||
"login": "JerboaBurrow", | ||
"id": 109722648, | ||
"node_id": "O_kgDOBoo8GA", | ||
"url": "https://api.github.com/orgs/JerboaBurrow", | ||
"repos_url": "https://api.github.com/orgs/JerboaBurrow/repos", | ||
"events_url": "https://api.github.com/orgs/JerboaBurrow/events", | ||
"hooks_url": "https://api.github.com/orgs/JerboaBurrow/hooks", | ||
"issues_url": "https://api.github.com/orgs/JerboaBurrow/issues", | ||
"members_url": "https://api.github.com/orgs/JerboaBurrow/members{/member}", | ||
"public_members_url": "https://api.github.com/orgs/JerboaBurrow/public_members{/member}", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/109722648?v=4", | ||
"description": "Creating apps and games" | ||
}, | ||
"sender": { | ||
"login": "Jerboa-app", | ||
"id": 84378622, | ||
"node_id": "MDQ6VXNlcjg0Mzc4NjIy", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/84378622?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/Jerboa-app", | ||
"html_url": "https://github.com/Jerboa-app", | ||
"followers_url": "https://api.github.com/users/Jerboa-app/followers", | ||
"following_url": "https://api.github.com/users/Jerboa-app/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/Jerboa-app/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/Jerboa-app/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/Jerboa-app/subscriptions", | ||
"organizations_url": "https://api.github.com/users/Jerboa-app/orgs", | ||
"repos_url": "https://api.github.com/users/Jerboa-app/repos", | ||
"events_url": "https://api.github.com/users/Jerboa-app/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/Jerboa-app/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
} | ||
}"#; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.