-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d10a2
commit e8d017a
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::github::{IssuesAction, PrState}; | ||
use crate::{github::Event, handlers::Context}; | ||
|
||
pub(crate) async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> { | ||
let Event::Issue(event) = event else { | ||
return Ok(()); | ||
}; | ||
// Note that this filters out reopened too, which is what we'd expect when we set the state | ||
// back to opened after closing. | ||
if event.action != IssuesAction::Opened { | ||
return Ok(()); | ||
} | ||
if !event.issue.is_pr() { | ||
return Ok(()); | ||
} | ||
|
||
// avoid acting on our own open events, otherwise we'll infinitely loop | ||
if event.sender.login == ctx.username { | ||
return Ok(()); | ||
} | ||
|
||
// If it's not the github-actions bot, we don't expect this handler to be needed. Skip the | ||
// event. | ||
if event.sender.login != "app/github-actions" { | ||
return Ok(()); | ||
} | ||
|
||
ctx.github | ||
.set_pr_state( | ||
event.issue.repository(), | ||
event.issue.number, | ||
PrState::Closed, | ||
) | ||
.await?; | ||
ctx.github | ||
.set_pr_state(event.issue.repository(), event.issue.number, PrState::Open) | ||
.await?; | ||
|
||
Ok(()) | ||
} |