Skip to content

Commit 26f8e42

Browse files
committed
Skipping comments to issues which aren't open anymore.
1 parent 6b0729d commit 26f8e42

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/github/nag.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,7 @@ impl<'a> RfcBotCommand<'a> {
614614
}
615615

616616
struct RfcBotComment<'a> {
617-
repository: &'a str,
618-
issue_num: i32,
617+
issue: &'a Issue,
619618
comment_type: CommentType<'a>,
620619
}
621620

@@ -637,8 +636,7 @@ impl<'a> RfcBotComment<'a> {
637636
fn new(issue: &'a Issue, comment_type: CommentType<'a>) -> RfcBotComment<'a> {
638637

639638
RfcBotComment {
640-
repository: &issue.repository,
641-
issue_num: issue.number,
639+
issue: &issue,
642640
comment_type: comment_type,
643641
}
644642
}
@@ -731,9 +729,9 @@ impl<'a> RfcBotComment<'a> {
731729

732730
fn add_comment_url(&self, msg: &mut String, comment_id: i32) {
733731
msg.push_str("https://github.com/");
734-
msg.push_str(&self.repository);
732+
msg.push_str(&self.issue.repository);
735733
msg.push_str("/issues/");
736-
msg.push_str(&self.issue_num.to_string());
734+
msg.push_str(&self.issue.number.to_string());
737735
msg.push_str("#issuecomment-");
738736
msg.push_str(&comment_id.to_string());
739737
}
@@ -745,17 +743,25 @@ impl<'a> RfcBotComment<'a> {
745743

746744
if CONFIG.post_comments {
747745

748-
let text = self.format()?;
746+
if self.issue.open {
747+
let text = self.format()?;
749748

750-
Ok(match existing_comment {
751-
Some(comment_id) => GH.edit_comment(self.repository, comment_id, &text),
752-
None => GH.new_comment(self.repository, self.issue_num, &text),
753-
}?)
749+
Ok(match existing_comment {
750+
Some(comment_id) => GH.edit_comment(&self.issue.repository, comment_id, &text),
751+
None => GH.new_comment(&self.issue.repository, self.issue.number, &text),
752+
}?)
753+
} else {
754+
info!("Skipping comment to {}#{}, the issue is no longer open",
755+
self.issue.repository,
756+
self.issue.number);
757+
758+
Err(DashError::Misc(None))
759+
}
754760

755761
} else {
756762
info!("Skipping comment to {}#{}, comment posts are disabled.",
757-
self.repository,
758-
self.issue_num);
763+
self.issue.repository,
764+
self.issue.number);
759765
Err(DashError::Misc(None))
760766
}
761767
}

0 commit comments

Comments
 (0)