Skip to content

Commit

Permalink
Merge pull request #83 from Alokit-Innovations/mkp/gh/process-review-…
Browse files Browse the repository at this point in the history
…test

Mkp/gh/process review test
  • Loading branch information
MuskanPaliwal authored Nov 13, 2023
2 parents a4e651b + 9b195e7 commit b00928a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 15 additions & 3 deletions vibi-dpu/src/db/prs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,25 @@ pub async fn github_process_and_update_pr_if_different(webhook_data: &Value, rep
return true;
}
if event_action == "synchronize" {
println!("[github_process_and_update_pr_if_different|update_pr_info_in_db] repo_owner: {}, repo_name: {}, pr_info_parsed: {:?}, pr_number: {}", &repo_owner, &repo_name, &pr_info_parsed, &pr_number);
println!("[github_process_and_update_pr_if_different| event_action synchronise] pr_info_parsed: {:?}", &pr_info_parsed);
update_pr_info_in_db(&repo_owner, &repo_name, &pr_info_parsed, &pr_number, repo_provider).await;
return true // commits are different, and PR info should be updated
}
if event_action == "submitted" {
let event_review_status = webhook_data["review"]["state"].to_string().trim_matches('"').to_string();
if event_review_status == "approved" {
println!("[github_process_and_update_pr_if_different| pr has been approved] pr_info_parsed: {:?}", &pr_info_parsed);
update_pr_info_in_db(&repo_owner, &repo_name, &pr_info_parsed, &pr_number, repo_provider).await;
return true
} else {
println!("[github_process_and_update_pr_if_different|no_update_needed] event is not approved");
return false; // event is not open or synchronize
}
} else {
println!("[github_process_and_update_pr_if_different|no_update_needed] event is not open or synchronize");
return false; // event is not open or synchronize
println!("[github_process_and_update_pr_if_different | no update needed] event is not opened or synchronise or approved");
return false;
}

}

fn parse_github_webhook_data(webhook_data: &Value) -> Option<PrInfo> {
Expand Down
5 changes: 3 additions & 2 deletions vibi-dpu/src/pubsub/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,16 @@ async fn process_webhook_callback(deserialised_msg_data: &Value) -> bool {
println!("[process_webhook_callback] {}", deserialised_msg_data);
let repo_provider = deserialised_msg_data["repositoryProvider"].to_string().trim_matches('"').to_string();
let mut is_reviewable = false;
if repo_provider== ProviderEnum::Github.to_string().to_lowercase() {
if repo_provider == ProviderEnum::Github.to_string().to_lowercase() {
let repo_owner = deserialised_msg_data["eventPayload"]["repository"]["owner"]["login"].to_string().trim_matches('"').to_string();
let repo_name = deserialised_msg_data["eventPayload"]["repository"]["name"].to_string().trim_matches('"').to_string();
let pr_number = deserialised_msg_data["eventPayload"]["pull_request"]["number"].to_string().trim_matches('"').to_string();
let event_type = deserialised_msg_data["eventType"].to_string().trim_matches('"').to_string();

println!("[process_webhook_callback] {}, {}, {}, {}", event_type, repo_owner, repo_name, pr_number);
if event_type == "pull_request_review" {
todo!("decide what to do in the case")
println!("[process_webhook_callback] Github PR review event");
is_reviewable = github_process_and_update_pr_if_different(&deserialised_msg_data["eventPayload"], &repo_owner, &repo_name, &pr_number, &repo_provider).await;
}
if event_type == "pull_request" {
println!("[process_webhook_callback] Github PR opened");
Expand Down

0 comments on commit b00928a

Please sign in to comment.