1- //! This handler is used to "relink" linked GitHub issues into their long form
1+ //! This handler is used to canonicalize linked GitHub issues into their long form
22//! so that when pulling subtree into the main repository we don't accidentaly
3- //! closes issue in the wrong repository.
3+ //! close issues in the wrong repository.
44//!
55//! Example: `Fixes #123` (in rust-lang/clippy) would now become `Fixes rust-lang/clippy#123`
66
@@ -10,8 +10,8 @@ use std::sync::LazyLock;
1010use regex:: Regex ;
1111
1212use crate :: {
13- config:: RelinkConfig ,
14- github:: { Event , IssuesAction , IssuesEvent } ,
13+ config:: CanonicalizeIssueLinksConfig ,
14+ github:: { IssuesAction , IssuesEvent } ,
1515 handlers:: Context ,
1616} ;
1717
@@ -21,34 +21,44 @@ static LINKED_RE: LazyLock<Regex> = LazyLock::new(|| {
2121 . unwrap ( )
2222} ) ;
2323
24- pub async fn handle ( ctx : & Context , event : & Event , config : & RelinkConfig ) -> anyhow:: Result < ( ) > {
25- let Event :: Issue ( e) = event else {
26- return Ok ( ( ) ) ;
27- } ;
24+ pub ( super ) struct CanonicalizeIssueLinksInput { }
2825
29- if !e. issue . is_pr ( ) {
30- return Ok ( ( ) ) ;
26+ pub ( super ) async fn parse_input (
27+ _ctx : & Context ,
28+ event : & IssuesEvent ,
29+ config : Option < & CanonicalizeIssueLinksConfig > ,
30+ ) -> Result < Option < CanonicalizeIssueLinksInput > , String > {
31+ if !event. issue . is_pr ( ) {
32+ return Ok ( None ) ;
3133 }
3234
33- if let Err ( e) = relink_pr ( & ctx, & e, config) . await {
34- tracing:: error!( "Error relinking pr: {:?}" , e) ;
35+ if !matches ! (
36+ event. action,
37+ IssuesAction :: Opened | IssuesAction :: Reopened | IssuesAction :: Edited
38+ ) {
39+ return Ok ( None ) ;
3540 }
3641
37- Ok ( ( ) )
42+ // Require a `[canoncalize-issue-links]` configuration block to enable the handler.
43+ if config. is_none ( ) {
44+ return Ok ( None ) ;
45+ } ;
46+
47+ Ok ( Some ( CanonicalizeIssueLinksInput { } ) )
3848}
3949
40- async fn relink_pr ( ctx : & Context , e : & IssuesEvent , _config : & RelinkConfig ) -> anyhow:: Result < ( ) > {
41- if e. action == IssuesAction :: Opened
42- || e. action == IssuesAction :: Reopened
43- || e. action == IssuesAction :: Edited
44- {
45- let full_repo_name = e. issue . repository ( ) . full_repo_name ( ) ;
50+ pub ( super ) async fn handle_input (
51+ ctx : & Context ,
52+ _config : & CanonicalizeIssueLinksConfig ,
53+ e : & IssuesEvent ,
54+ _input : CanonicalizeIssueLinksInput ,
55+ ) -> anyhow:: Result < ( ) > {
56+ let full_repo_name = e. issue . repository ( ) . full_repo_name ( ) ;
4657
47- let new_body = fix_linked_issues ( & e. issue . body , full_repo_name. as_str ( ) ) ;
58+ let new_body = fix_linked_issues ( & e. issue . body , full_repo_name. as_str ( ) ) ;
4859
49- if e. issue . body != new_body {
50- e. issue . edit_body ( & ctx. github , & new_body) . await ?;
51- }
60+ if e. issue . body != new_body {
61+ e. issue . edit_body ( & ctx. github , & new_body) . await ?;
5262 }
5363
5464 Ok ( ( ) )
0 commit comments