Skip to content

Commit ba06812

Browse files
committed
Update to new networking SDK
Signed-off-by: Michael Yuan <[email protected]>
1 parent 02be49a commit ba06812

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

.cargo/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[build]
2+
target="wasm32-wasi"
3+
rustflags = ["--cfg", "wasmedge", "--cfg", "tokio_unstable"]
4+
5+
6+
[target.wasm32-wasi]
7+
runner = "wasmedge"

Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ name = "github-pr-summary"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[patch.crates-io]
7+
tokio = { git = "https://github.com/second-state/wasi_tokio.git", branch = "v1.36.x" }
8+
socket2 = { git = "https://github.com/second-state/socket2.git", branch = "v0.5.x" }
9+
hyper = { git = "https://github.com/second-state/wasi_hyper.git", branch = "v0.14.x" }
10+
reqwest = { git = "https://github.com/second-state/wasi_reqwest.git", branch = "0.11.x" }
11+
612
[lib]
713
path = "src/github-pr-summary.rs"
814
crate-type = ["cdylib"]
915

1016
[dependencies]
1117
dotenv = "0.15.0"
12-
github-flows = "0.6"
18+
github-flows = "0.8"
1319
serde = { version = "1.0", features = ["derive"] }
1420
serde_json = "1.0.93"
15-
tokio_wasi = { version = "1.25.1", features = ["macros", "rt"] }
1621
anyhow = "1"
1722
flowsnet-platform-sdk = "0.1"
1823
lazy_static = "1.4.0"
1924
regex = "1.7.1"
2025
llmservice-flows = "0.2.0"
2126
words-count = "0.1.4"
2227
log = "0.4"
28+
tokio = { version = "1", features = ["rt", "macros", "net", "time"] }

src/github-pr-summary.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use dotenv::dotenv;
22
use flowsnet_platform_sdk::logger;
33
use github_flows::{
44
event_handler, get_octo, listen_to_event,
5-
octocrab::models::events::payload::{EventPayload, IssueCommentEventAction, PullRequestEventAction},
65
octocrab::models::CommentId,
6+
octocrab::models::webhook_events::{WebhookEvent, WebhookEventPayload},
7+
octocrab::models::webhook_events::payload::{IssueCommentWebhookEventAction, PullRequestWebhookEventAction},
78
GithubLogin,
89
};
910
use llmservice_flows::{
@@ -26,7 +27,7 @@ pub async fn on_deploy() {
2627
}
2728

2829
#[event_handler]
29-
async fn handler(payload: EventPayload) {
30+
async fn handler(event: Result<WebhookEvent, serde_json::Error>) {
3031
dotenv().ok();
3132
logger::init();
3233
log::debug!("Running github-pr-summary/main handler()");
@@ -43,12 +44,13 @@ async fn handler(payload: EventPayload) {
4344
// This is measured in chars. We set it to be 2x llm_ctx_size, which is measured in tokens.
4445
let ctx_size_char : usize = (2 * llm_ctx_size).try_into().unwrap_or(0);
4546

47+
let payload = event.unwrap();
4648
let mut new_commit : bool = false;
47-
let (title, pull_number, _contributor) = match payload {
48-
EventPayload::PullRequestEvent(e) => {
49-
if e.action == PullRequestEventAction::Opened {
49+
let (title, pull_number, _contributor) = match payload.specific {
50+
WebhookEventPayload::PullRequest(e) => {
51+
if e.action == PullRequestWebhookEventAction::Opened {
5052
log::debug!("Received payload: PR Opened");
51-
} else if e.action == PullRequestEventAction::Synchronize {
53+
} else if e.action == PullRequestWebhookEventAction::Synchronize {
5254
new_commit = true;
5355
log::debug!("Received payload: PR Synced");
5456
} else {
@@ -62,8 +64,8 @@ async fn handler(payload: EventPayload) {
6264
p.user.unwrap().login,
6365
)
6466
}
65-
EventPayload::IssueCommentEvent(e) => {
66-
if e.action == IssueCommentEventAction::Deleted {
67+
WebhookEventPayload::IssueComment(e) => {
68+
if e.action == IssueCommentWebhookEventAction::Deleted {
6769
log::debug!("Deleted issue comment");
6870
return;
6971
}
@@ -75,7 +77,7 @@ async fn handler(payload: EventPayload) {
7577
// return;
7678
// }
7779
// TODO: Makeshift but operational
78-
if body.starts_with("Hello, I am a [PR summary bot]") {
80+
if body.starts_with("Hello, I am a [PR summary agent]") {
7981
log::info!("Ignore comment via bot");
8082
return;
8183
};
@@ -85,6 +87,7 @@ async fn handler(payload: EventPayload) {
8587
return;
8688
}
8789

90+
log::debug!("Will process comment event: {:?}", &body);
8891
(e.issue.title, e.issue.number, e.issue.user.login)
8992
}
9093
_ => return,
@@ -94,11 +97,11 @@ async fn handler(payload: EventPayload) {
9497
let issues = octo.issues(owner.clone(), repo.clone());
9598
let mut comment_id: CommentId = 0u64.into();
9699
if new_commit {
97-
// Find the first "Hello, I am a [PR summary bot]" comment to update
100+
// Find the first "Hello, I am a [PR summary agent]" comment to update
98101
match issues.list_comments(pull_number).send().await {
99102
Ok(comments) => {
100103
for c in comments.items {
101-
if c.body.unwrap_or_default().starts_with("Hello, I am a [PR summary bot]") {
104+
if c.body.unwrap_or_default().starts_with("Hello, I am a [PR summary agent]") {
102105
comment_id = c.id;
103106
break;
104107
}
@@ -111,7 +114,7 @@ async fn handler(payload: EventPayload) {
111114
}
112115
} else {
113116
// PR OPEN or Trigger phrase: create a new comment
114-
match issues.create_comment(pull_number, "Hello, I am a [PR summary bot](https://github.com/flows-network/github-pr-summary/) on [flows.network](https://flows.network/).\n\nIt could take a few minutes for me to analyze this PR. Relax, grab a cup of coffee and check back later. Thanks!").await {
117+
match issues.create_comment(pull_number, "Hello, I am a [PR summary agent](https://github.com/flows-network/github-pr-summary/) on [flows.network](https://flows.network/).\n\nIt could take a few minutes for me to analyze this PR. Relax, grab a cup of coffee and check back later. Thanks!").await {
115118
Ok(comment) => {
116119
comment_id = comment.id;
117120
}
@@ -193,7 +196,7 @@ async fn handler(payload: EventPayload) {
193196
}
194197

195198
let mut resp = String::new();
196-
resp.push_str("Hello, I am a [PR summary bot](https://github.com/flows-network/github-pr-summary/) on [flows.network](https://flows.network/). Here are my reviews of code commits in this PR.\n\n------\n\n");
199+
resp.push_str("Hello, I am a [PR summary agent](https://github.com/flows-network/github-pr-summary/) on [flows.network](https://flows.network/). Here are my reviews of code commits in this PR.\n\n------\n\n");
197200
if reviews.len() > 1 {
198201
log::debug!("Sending all reviews to LLM for summarization");
199202
let co = ChatOptions {

0 commit comments

Comments
 (0)