Skip to content

Commit 555cb07

Browse files
authored
Do not perform a merge instead post comment (#12)
1 parent 050821a commit 555cb07

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

src/github.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -779,27 +779,6 @@ impl Issue {
779779
Ok(())
780780
}
781781

782-
pub async fn merge(&self, client: &GithubClient) -> anyhow::Result<()> {
783-
let merge_url = format!("{}/pulls/{}/merge", self.repository().url(), self.number);
784-
785-
// change defaults by reading from somewhere, maybe in .toml?
786-
#[derive(serde::Serialize)]
787-
struct MergeIssue<'a> {
788-
commit_title: &'a str,
789-
merge_method: &'a str,
790-
}
791-
792-
client
793-
._send_req(client.put(&merge_url).json(&MergeIssue {
794-
commit_title: "Merged by the bot!",
795-
merge_method: "merge",
796-
}))
797-
.await
798-
.context("failed to merge issue")?;
799-
800-
Ok(())
801-
}
802-
803782
/// Returns the diff in this event, for Open and Synchronize events for now.
804783
pub async fn diff(&self, client: &GithubClient) -> anyhow::Result<Option<String>> {
805784
let (before, after) = if let (Some(base), Some(head)) = (&self.base, &self.head) {

src/handlers/jobs.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
// Further info could be find in src/jobs.rs
66
use super::Context;
7+
use crate::db::issue_decision_state::get_issue_decision_state;
78
use crate::github::*;
89
use crate::handlers::decision::{DecisionProcessActionMetadata, DECISION_PROCESS_JOB_NAME};
10+
use crate::interactions::PingComment;
911
use parser::command::decision::Resolution::{Hold, Merge};
1012
use reqwest::Client;
13+
use tokio_postgres::Client as DbClient;
1114
use tracing as log;
1215

1316
pub async fn handle_job(
@@ -22,7 +25,8 @@ pub async fn handle_job(
2225
Ok(())
2326
}
2427
matched_name if *matched_name == DECISION_PROCESS_JOB_NAME.to_string() => {
25-
decision_process_handler(&metadata).await
28+
let db = ctx.db.get().await;
29+
decision_process_handler(&db, &metadata).await
2630
}
2731
_ => default(&name, &metadata),
2832
}
@@ -38,7 +42,10 @@ fn default(name: &String, metadata: &serde_json::Value) -> anyhow::Result<()> {
3842
Ok(())
3943
}
4044

41-
async fn decision_process_handler(metadata: &serde_json::Value) -> anyhow::Result<()> {
45+
async fn decision_process_handler(
46+
db: &DbClient,
47+
metadata: &serde_json::Value,
48+
) -> anyhow::Result<()> {
4249
tracing::trace!(
4350
"handle_job fell into decision process case: (metadata={:?})",
4451
metadata
@@ -50,7 +57,22 @@ async fn decision_process_handler(metadata: &serde_json::Value) -> anyhow::Resul
5057

5158
match gh_client.json::<Issue>(request).await {
5259
Ok(issue) => match metadata.status {
53-
Merge => issue.merge(&gh_client).await?,
60+
Merge => {
61+
let users: Vec<String> = get_issue_decision_state(&db, &issue.number)
62+
.await
63+
.unwrap()
64+
.current
65+
.into_keys()
66+
.collect();
67+
let users_ref: Vec<&str> = users.iter().map(|x| x.as_ref()).collect();
68+
69+
let cmnt = PingComment::new(
70+
&issue,
71+
&users_ref,
72+
"The final comment period has resolved, with a decision to **merge**. Ping involved once again.",
73+
);
74+
cmnt.post(&gh_client).await?;
75+
}
5476
Hold => issue.close(&gh_client).await?,
5577
},
5678
Err(e) => log::error!(

src/interactions.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,25 @@ impl<'a> ErrorComment<'a> {
3333
pub struct PingComment<'a> {
3434
issue: &'a Issue,
3535
users: &'a [&'a str],
36+
message: String,
3637
}
3738

3839
impl<'a> PingComment<'a> {
39-
pub fn new(issue: &'a Issue, users: &'a [&str]) -> PingComment<'a> {
40-
PingComment { issue, users }
40+
pub fn new<T>(issue: &'a Issue, users: &'a [&str], message: T) -> PingComment<'a>
41+
where
42+
T: Into<String>,
43+
{
44+
PingComment {
45+
issue,
46+
users,
47+
message: message.into(),
48+
}
4149
}
4250

4351
pub async fn post(&self, client: &GithubClient) -> anyhow::Result<()> {
4452
let mut body = String::new();
53+
writeln!(body, "{}", self.message)?;
54+
writeln!(body)?;
4555
for user in self.users {
4656
write!(body, "@{} ", user)?;
4757
}

0 commit comments

Comments
 (0)