-
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.
Merge pull request #15 from JerboaBurrow/add_fork_issue_pr
adds fork event
- Loading branch information
Showing
9 changed files
with
1,134 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "pulse" | ||
version = "0.0.4" | ||
version = "0.0.5" | ||
authors = ["Jerboa"] | ||
|
||
edition="2021" | ||
|
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
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 = "issues"; | ||
|
||
pub struct GithubIssue | ||
{ | ||
config: EventConfig | ||
} | ||
|
||
impl GithubIssue | ||
{ | ||
pub fn new() -> GithubIssue | ||
{ | ||
GithubIssue { config: EventConfig::new() } | ||
} | ||
} | ||
|
||
impl Event for GithubIssue | ||
{ | ||
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_issue"); | ||
} | ||
|
||
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!("issue 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
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 = "pull_request"; | ||
|
||
pub struct GithubPullRequest | ||
{ | ||
config: EventConfig | ||
} | ||
|
||
impl GithubPullRequest | ||
{ | ||
pub fn new() -> GithubPullRequest | ||
{ | ||
GithubPullRequest { config: EventConfig::new() } | ||
} | ||
} | ||
|
||
impl Event for GithubPullRequest | ||
{ | ||
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_pull_request"); | ||
} | ||
|
||
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!("pull_request 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
Oops, something went wrong.