Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Jun 25, 2024
1 parent 1f168f8 commit 0c8e09e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ pub const TXT_CUPRATE_MEETING_PREFIX: &str = "[Cuprate](https://github.com/Cupra
Location: [Libera.chat, #cuprate](https://libera.chat/) | [Matrix](https://matrix.to/#/#cuprate:monero.social?via=matrix.org&via=monero.social)
Note that there are currently communication issues with Matrix accounts created on the matrix.org server, consider using a different homeserver to see messages.
> Note that there are currently communication issues with Matrix accounts created on the matrix.org server, consider using a different homeserver to see messages.
[Join the Monero Matrix server if you don't already have a Matrix account](https://www.getmonero.org/resources/user-guides/join-monero-matrix.html)
Time: 18:00 UTC [Check in your timezone](https://www.timeanddate.com/worldclock/converter.html)
Moderator: @boog900
Moderator: @Boog900
Please comment on GitHub in advance of the meeting if you would like to propose a discussion topic.
Expand Down
91 changes: 41 additions & 50 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//---------------------------------------------------------------------------------------------------- Use
use anyhow::anyhow;
use reqwest::Client;
use reqwest::{Client, RequestBuilder};
use serde::{Deserialize, Serialize};
use serde_json::{from_str, json};
use tracing::{info, instrument, trace};
Expand All @@ -15,6 +15,17 @@ use crate::{
pull_request::{PullRequest, PullRequestError},
};

//---------------------------------------------------------------------------------------------------- Free
/// TODO
fn build_client() -> Result<Client, anyhow::Error> {
let client = reqwest::ClientBuilder::new()
.gzip(true)
.user_agent(MOO_USER_AGENT)
.build()?;

Ok(client)
}

//---------------------------------------------------------------------------------------------------- Event
/// TODO
///
Expand All @@ -26,18 +37,9 @@ pub async fn pr_is_open(pr: PullRequest) -> Result<bool, PullRequestError> {
let url = format!("{CUPRATE_GITHUB_PULL_API}/{pr}");
trace!("PR url: {url}");

let client = match reqwest::ClientBuilder::new()
.gzip(true)
.user_agent(MOO_USER_AGENT)
.build()
{
let client = match build_client() {
Ok(c) => c,
Err(e) => {
return Err(PullRequestError::Other {
pr,
error: e.into(),
})
}
Err(error) => return Err(PullRequestError::Other { pr, error }),
};

let req = match client.get(url).send().await {
Expand Down Expand Up @@ -86,6 +88,20 @@ pub async fn pr_is_open(pr: PullRequest) -> Result<bool, PullRequestError> {
}

//---------------------------------------------------------------------------------------------------- Issues
/// TODO
trait AddGithubHeaders {
/// TODO
fn add_github_headers(self) -> Self;
}

impl AddGithubHeaders for RequestBuilder {
fn add_github_headers(self) -> Self {
self.header("Accept", "application/vnd.github+json")
.header("X-GitHub-Api-Version", "2022-11-28")
.header("Authorization", format!("Bearer {}", CONFIG.token))
}
}

/// TODO
///
/// # Errors
Expand All @@ -95,10 +111,7 @@ pub async fn pr_is_open(pr: PullRequest) -> Result<bool, PullRequestError> {
pub async fn finish_cuprate_meeting(
meeting_logs: String,
) -> Result<(String, String), anyhow::Error> {
let client = reqwest::ClientBuilder::new()
.gzip(true)
.user_agent(MOO_USER_AGENT)
.build()?;
let client = build_client()?;

let (issue, title) = find_cuprate_meeting_issue(&client, false).await?;
let logs = post_comment_in_issue(&client, issue, meeting_logs).await?;
Expand All @@ -122,9 +135,7 @@ pub async fn find_cuprate_meeting_issue(

let body = client
.get(MONERO_META_GITHUB_ISSUE_API)
.header("Accept", "application/vnd.github+json")
.header("X-GitHub-Api-Version", "2022-11-28")
.header("Authorization", format!("Bearer {}", CONFIG.token))
.add_github_headers()
.query(&[("state", "all")])
.send()
.await?
Expand Down Expand Up @@ -186,23 +197,14 @@ pub async fn post_cuprate_meeting_issue(
trace!("Posting Cuprate meeting issue on: {MONERO_META_GITHUB_ISSUE_API}");

let next_meeting_iso_8601 = {
use chrono::{prelude::*, Days, Weekday};

let mut today = Utc::now().date_naive();

while today.weekday() == Weekday::Tue {
println!("{today}");
today = today + Days::new(1);
}

while today.weekday() != Weekday::Tue {
println!("{today}");
today = today + Days::new(1);
}

today.format("%Y-%m-%d").to_string()
use chrono::{prelude::*, Days};
let today = Utc::now().date_naive();
let next = today + Days::new(7);
next.format("%Y-%m-%d").to_string()
};

info!("Next meeting date: {next_meeting_iso_8601}");

let next_meeting_number = {
let mut iter = previous_meeting_title.split_whitespace();

Expand Down Expand Up @@ -248,9 +250,7 @@ pub async fn post_cuprate_meeting_issue(

let body = client
.post(MONERO_META_GITHUB_ISSUE_API)
.header("Accept", "application/vnd.github+json")
.header("X-GitHub-Api-Version", "2022-11-28")
.header("Authorization", format!("Bearer {}", CONFIG.token))
.add_github_headers()
.body(body.to_string())
.send()
.await?
Expand Down Expand Up @@ -289,9 +289,7 @@ pub async fn post_comment_in_issue(

let body = client
.post(url)
.header("Accept", "application/vnd.github+json")
.header("X-GitHub-Api-Version", "2022-11-28")
.header("Authorization", format!("Bearer {}", CONFIG.token))
.add_github_headers()
.body(json!({"body":comment}).to_string())
.send()
.await?
Expand Down Expand Up @@ -336,9 +334,7 @@ pub async fn close_issue(client: &Client, issue: u64) -> Result<(), anyhow::Erro

let body = client
.patch(url)
.header("Accept", "application/vnd.github+json")
.header("X-GitHub-Api-Version", "2022-11-28")
.header("Authorization", format!("Bearer {}", CONFIG.token))
.add_github_headers()
.body(body.to_string())
.send()
.await?
Expand Down Expand Up @@ -375,10 +371,7 @@ pub async fn close_issue(client: &Client, issue: u64) -> Result<(), anyhow::Erro
#[instrument]
#[inline]
pub async fn edit_cuprate_meeting_agenda(new_items: Vec<String>) -> Result<String, anyhow::Error> {
let client = reqwest::ClientBuilder::new()
.gzip(true)
.user_agent(MOO_USER_AGENT)
.build()?;
let client = build_client()?;

let current_issue = find_cuprate_meeting_issue(&client, false).await?.0;
let last_issue = find_cuprate_meeting_issue(&client, true).await?.0;
Expand Down Expand Up @@ -409,9 +402,7 @@ pub async fn edit_cuprate_meeting_agenda(new_items: Vec<String>) -> Result<Strin

let body = client
.patch(&url)
.header("Accept", "application/vnd.github+json")
.header("X-GitHub-Api-Version", "2022-11-28")
.header("Authorization", format!("Bearer {}", CONFIG.token))
.add_github_headers()
.body(body.to_string())
.send()
.await?
Expand Down

0 comments on commit 0c8e09e

Please sign in to comment.