@@ -2,6 +2,7 @@ use anyhow::{Context as _, Result};
2
2
use octocrab:: Octocrab ;
3
3
4
4
mod analyzer;
5
+ mod commenter;
5
6
mod config;
6
7
mod report_generator;
7
8
@@ -56,90 +57,97 @@ async fn main() -> Result<()> {
56
57
& config. head_branch ,
57
58
) ;
58
59
59
- // 4. Post the report as a comment or update existing comment
60
+ // Post or update the report as a PR comment
61
+ let commenter =
62
+ commenter:: Commenter :: new ( & octocrab, & config. owner , & config. repo , config. pr_number ) ;
60
63
61
- // Create a unique signature for the bot's comments
62
- let bot_signature = "<!-- clippy-annotation-reporter-comment -->" ;
63
- let report_with_signature = format ! ( "{}\n \n {}" , report, bot_signature) ;
64
+ commenter. run ( report) . await ?;
64
65
65
- // Search for existing comment by the bot
66
- println ! ( "Checking for existing comment on PR #{}" , config. pr_number) ;
67
- let existing_comment = find_existing_comment (
68
- & octocrab,
69
- & config. owner ,
70
- & config. repo ,
71
- config. pr_number ,
72
- bot_signature,
73
- )
74
- . await ?;
66
+ println ! ( "Process completed successfully!" ) ;
75
67
76
- // Update existing comment or create a new one
77
- if let Some ( comment_id) = existing_comment {
78
- println ! ( "Updating existing comment #{}" , comment_id) ;
79
- octocrab
80
- . issues ( & config. owner , & config. repo )
81
- . update_comment ( comment_id. into ( ) , report_with_signature)
82
- . await
83
- . context ( "Failed to update existing comment" ) ?;
84
- println ! ( "Comment updated successfully!" ) ;
85
- } else {
86
- println ! ( "Creating new comment on PR #{}" , config. pr_number) ;
87
- octocrab
88
- . issues ( & config. owner , & config. repo )
89
- . create_comment ( config. pr_number , report_with_signature)
90
- . await
91
- . context ( "Failed to post comment to PR" ) ?;
92
- println ! ( "Comment created successfully!" ) ;
93
- }
68
+ // 4. Post the report as a comment or update existing comment
69
+
70
+ // Create a unique signature for the bot's comments
71
+ // let bot_signature = "<!-- clippy-annotation-reporter-comment -->";
72
+ // let report_with_signature = format!("{}\n\n{}", report, bot_signature);
73
+ //
74
+ // // Search for existing comment by the bot
75
+ // println!("Checking for existing comment on PR #{}", config.pr_number);
76
+ // let existing_comment = find_existing_comment(
77
+ // &octocrab,
78
+ // &config.owner,
79
+ // &config.repo,
80
+ // config.pr_number,
81
+ // bot_signature,
82
+ // )
83
+ // .await?;
84
+ //
85
+ // // Update existing comment or create a new one
86
+ // if let Some(comment_id) = existing_comment {
87
+ // println!("Updating existing comment #{}", comment_id);
88
+ // octocrab
89
+ // .issues(&config.owner, &config.repo)
90
+ // .update_comment(comment_id.into(), report_with_signature)
91
+ // .await
92
+ // .context("Failed to update existing comment")?;
93
+ // println!("Comment updated successfully!");
94
+ // } else {
95
+ // println!("Creating new comment on PR #{}", config.pr_number);
96
+ // octocrab
97
+ // .issues(&config.owner, &config.repo)
98
+ // .create_comment(config.pr_number, report_with_signature)
99
+ // .await
100
+ // .context("Failed to post comment to PR")?;
101
+ // println!("Comment created successfully!");
102
+ // }
94
103
95
104
Ok ( ( ) )
96
105
}
97
106
98
- /// Find existing comment by the bot on a PR
99
- async fn find_existing_comment (
100
- octocrab : & Octocrab ,
101
- owner : & str ,
102
- repo : & str ,
103
- pr_number : u64 ,
104
- signature : & str ,
105
- ) -> Result < Option < u64 > > {
106
- // Get all comments on the PR
107
- let mut page = octocrab
108
- . issues ( owner, repo)
109
- . list_comments ( pr_number)
110
- . per_page ( 100 )
111
- . send ( )
112
- . await
113
- . context ( "Failed to list PR comments" ) ?;
114
-
115
- // Process current and subsequent pages
116
- loop {
117
- for comment in & page {
118
- if comment
119
- . body
120
- . as_ref ( )
121
- . map_or ( false , |body| body. contains ( signature) )
122
- {
123
- return Ok ( Some ( * comment. id ) ) ;
124
- }
125
- }
126
-
127
- // Try to get the next page if it exists
128
- match octocrab. get_page ( & page. next ) . await {
129
- Ok ( Some ( next_page) ) => {
130
- page = next_page;
131
- }
132
- Ok ( None ) => {
133
- // No more pages
134
- break ;
135
- }
136
- Err ( e) => {
137
- println ! ( "Warning: Failed to fetch next page of comments: {}" , e) ;
138
- break ;
139
- }
140
- }
141
- }
142
-
143
- // No matching comment found
144
- Ok ( None )
145
- }
107
+ // async fn find_existing_comment(
108
+ // octocrab: &Octocrab,
109
+ // owner: &str,
110
+ // repo: &str,
111
+ // pr_number: u64,
112
+ // signature: &str,
113
+ // ) -> Result<Option<u64>> {
114
+ // // Get all comments on the PR
115
+ // let mut page = octocrab
116
+ // .issues(owner, repo)
117
+ // .list_comments(pr_number)
118
+ // .per_page(100)
119
+ // .send()
120
+ // .await
121
+ // .context("Failed to list PR comments")?;
122
+ //
123
+ // // Process current and subsequent pages
124
+ // loop {
125
+ // for comment in &page {
126
+ // if comment
127
+ // .body
128
+ // .as_ref()
129
+ // .map_or(false, |body| body.contains(signature))
130
+ // {
131
+ // return Ok(Some(*comment.id));
132
+ // }
133
+ // }
134
+ //
135
+ // // Try to get the next page if it exists
136
+ // match octocrab.get_page(&page.next).await {
137
+ // Ok(Some(next_page)) => {
138
+ // page = next_page;
139
+ // }
140
+ // Ok(None) => {
141
+ // // No more pages
142
+ // break;
143
+ // }
144
+ // Err(e) => {
145
+ // println!("Warning: Failed to fetch next page of comments: {}", e);
146
+ // break;
147
+ // }
148
+ // }
149
+ // }
150
+ //
151
+ // // No matching comment found
152
+ // Ok(None)
153
+ // }
0 commit comments