-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add push, tag push, issue event handlers
- Loading branch information
Showing
12 changed files
with
189 additions
and
77 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
Empty file.
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,22 @@ | ||
use crate::http_server::GitlabEvent; | ||
|
||
pub fn handle_issue_event(gitlab_event: &GitlabEvent) -> String { | ||
let project = &gitlab_event.project; | ||
let project_name = &project.name; | ||
let project_url = &project.homepage; | ||
let user_name = &gitlab_event.user.as_ref().unwrap().name; | ||
let issue = &gitlab_event.object_attributes.as_ref().unwrap(); | ||
let issue_url = &issue.url; | ||
let issue_title = &issue.title; | ||
|
||
if issue.action.is_none() { | ||
return "".to_string(); | ||
} | ||
|
||
let issue_action = &issue.action.as_ref().unwrap(); | ||
|
||
format!( | ||
"<b>{}</b> {} issue <a href=\"{}\">{}</a> on <a href=\"{}\">{}</a>\n", | ||
user_name, issue_action, issue_url, issue_title, project_url, project_name | ||
) | ||
} |
Empty file.
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,9 @@ | ||
pub mod build; | ||
pub mod issue; | ||
pub mod merge_request; | ||
pub mod note; | ||
pub mod pipeline; | ||
pub mod push; | ||
pub mod tag_push; | ||
pub mod unknown_event; | ||
pub mod wiki_page; |
Empty file.
Empty file.
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,31 @@ | ||
use crate::http_server::GitlabEvent; | ||
|
||
pub fn handle_push_event(gitlab_event: &GitlabEvent) -> String { | ||
let branch_ref = &gitlab_event.r#ref.as_ref().unwrap(); | ||
let branch_name = branch_ref.split('/').last().unwrap(); | ||
let project = &gitlab_event.project; | ||
|
||
// replace - with \- to avoid error in telegram markdown | ||
let project_name = &project.name; | ||
let project_url = &project.homepage; | ||
|
||
let mut commit_paragraph = String::new(); | ||
|
||
for commit in gitlab_event.commits.as_ref().unwrap() { | ||
log::info!("Commit: {}", commit.message); | ||
log::info!("Commit url: {}", commit.url); | ||
log::info!("Commit author: {}", commit.author.name); | ||
|
||
let commit_url = &commit.url; | ||
let commit_message = &commit.message.trim_end(); | ||
let commit_author_name = &commit.author.name; | ||
|
||
// commit_paragraph.push_str(&format!("{}: [{}]({}) to [{}:{}]({})\n", commit_author_name, commit_message, commit_url, project_name, branch_name, project_url)); | ||
commit_paragraph.push_str(&format!( | ||
"<b>{}</b>: <a href=\"{}\">{}</a> to <a href=\"{}\">{}:{}</a>\n", | ||
commit_author_name, commit_url, commit_message, project_url, project_name, branch_name | ||
)); | ||
} | ||
|
||
commit_paragraph | ||
} |
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,18 @@ | ||
use crate::http_server::GitlabEvent; | ||
|
||
pub fn handle_tag_push_event(gitlab_event: &GitlabEvent) -> String { | ||
let tag_ref = &gitlab_event.r#ref.as_ref().unwrap(); | ||
let tag_name = tag_ref.split("refs/tags/").last().unwrap(); | ||
let project = &gitlab_event.project; | ||
|
||
// replace - with \- to avoid error in telegram markdown | ||
let project_name = &project.name; | ||
let project_url = &project.homepage; | ||
let tag_url = &format!("{}/-/tree/{}", project_url, tag_name); | ||
let user_name = &gitlab_event.user_name.as_ref().unwrap(); | ||
|
||
format!( | ||
"<b>{}</b> pushed a new tag <a href=\"{}\">{}</a> to <a href=\"{}\">{}</a>\n", | ||
user_name, tag_url, tag_name, project_url, project_name | ||
) | ||
} |
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,13 @@ | ||
use crate::http_server::GitlabEvent; | ||
|
||
pub fn handle_unknown_event(gitlab_event: &GitlabEvent) -> String { | ||
log::info!("Unknown event"); | ||
let project = &gitlab_event.project; | ||
let project_name = &project.name; | ||
let project_url = &project.homepage; | ||
|
||
format!( | ||
"Unknown event has triggered: {} on <a href=\"{}\">{}</a>\n", | ||
&gitlab_event.object_kind, project_url, project_name | ||
) | ||
} |
Empty file.