Skip to content

Commit

Permalink
update(bot): subcommand to use bot name instead of id (#18)
Browse files Browse the repository at this point in the history
Getting the bot id was pretty manually, instead we can use the bot name
instead.
  • Loading branch information
sbdchd authored Jun 21, 2020
1 parent bd592e3 commit 8953be0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,20 @@ pub fn comment_on_pr(
private_key: &str,
app_id: i64,
install_id: i64,
bot_id: i64,
bot_name: &str,
pr: PullRequest,
comment_body: String,
) -> Result<Value, GithubError> {
let jwt = generate_jwt(private_key, app_id)?;
let access_token = create_access_token(&jwt, install_id)?;
let comments = list_comments(&pr, &access_token.token)?;

match comments.iter().find(|x| x.user.id == bot_id) {
let bot_name = format!("{}[bot]", bot_name);

match comments
.iter()
.find(|x| x.user.r#type == "Bot" && x.user.login == bot_name)
{
Some(prev_comment) => update_comment(
&pr.owner,
&pr.repo,
Expand Down
10 changes: 5 additions & 5 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ pub enum Command {
/// GitHub Install Id. The installation that squawk is acting on.
#[structopt(long, env = "GITHUB_INSTALL_ID")]
github_install_id: i64,
/// GitHub Bot Id. The User id of the bot.
#[structopt(long, env = "GITHUB_BOT_ID")]
github_bot_id: i64,
/// GitHub Bot Name.
#[structopt(long, env = "GITHUB_BOT_NAME")]
github_bot_name: String,
/// GitHub Repo Owner
/// github.com/sbdchd/squawk, sbdchd is the owner
#[structopt(long, env = "GITHUB_REPO_OWNER")]
Expand All @@ -65,7 +65,7 @@ pub fn check_and_comment_on_pr(cmd: Command, is_stdin: bool) -> Result<i32, Squa
github_private_key,
github_app_id,
github_install_id,
github_bot_id,
github_bot_name,
github_repo_owner,
github_repo_name,
github_pr_number,
Expand All @@ -82,7 +82,7 @@ pub fn check_and_comment_on_pr(cmd: Command, is_stdin: bool) -> Result<i32, Squa
&github_private_key,
github_app_id,
github_install_id,
github_bot_id,
&github_bot_name,
pr,
comment_body,
)?;
Expand Down

0 comments on commit 8953be0

Please sign in to comment.