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
2
2
//! 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.
4
4
//!
5
5
//! Example: `Fixes #123` (in rust-lang/clippy) would now become `Fixes rust-lang/clippy#123`
6
6
@@ -10,8 +10,8 @@ use std::sync::LazyLock;
10
10
use regex:: Regex ;
11
11
12
12
use crate :: {
13
- config:: RelinkConfig ,
14
- github:: { Event , IssuesAction , IssuesEvent } ,
13
+ config:: CanonicalizeIssueLinksConfig ,
14
+ github:: { IssuesAction , IssuesEvent } ,
15
15
handlers:: Context ,
16
16
} ;
17
17
@@ -21,34 +21,44 @@ static LINKED_RE: LazyLock<Regex> = LazyLock::new(|| {
21
21
. unwrap ( )
22
22
} ) ;
23
23
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 { }
28
25
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 ) ;
31
33
}
32
34
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 ) ;
35
40
}
36
41
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 { } ) )
38
48
}
39
49
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 ( ) ;
46
57
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 ( ) ) ;
48
59
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 ?;
52
62
}
53
63
54
64
Ok ( ( ) )
0 commit comments