1
1
//! A scheduled job to post a PR to update the documentation on rust-lang/rust.
2
2
3
3
use crate :: db:: jobs:: JobSchedule ;
4
- use crate :: github:: { self , GitTreeEntry , GithubClient , Repository } ;
4
+ use crate :: github:: { self , GitTreeEntry , GithubClient , Issue , Repository } ;
5
5
use anyhow:: Context ;
6
6
use anyhow:: Result ;
7
7
use cron:: Schedule ;
@@ -56,10 +56,13 @@ pub async fn handle_job() -> Result<()> {
56
56
}
57
57
58
58
tracing:: trace!( "starting docs-update" ) ;
59
- docs_update ( ) . await . context ( "failed to process docs update" )
59
+ docs_update ( )
60
+ . await
61
+ . context ( "failed to process docs update" ) ?;
62
+ Ok ( ( ) )
60
63
}
61
64
62
- async fn docs_update ( ) -> Result < ( ) > {
65
+ pub async fn docs_update ( ) -> Result < Option < Issue > > {
63
66
let gh = GithubClient :: new_with_default_token ( Client :: new ( ) ) ;
64
67
let work_repo = gh. repository ( WORK_REPO ) . await ?;
65
68
work_repo
@@ -69,12 +72,11 @@ async fn docs_update() -> Result<()> {
69
72
let updates = get_submodule_updates ( & gh, & work_repo) . await ?;
70
73
if updates. is_empty ( ) {
71
74
tracing:: trace!( "no updates this week?" ) ;
72
- return Ok ( ( ) ) ;
75
+ return Ok ( None ) ;
73
76
}
74
77
75
78
create_commit ( & gh, & work_repo, & updates) . await ?;
76
- create_pr ( & gh, & updates) . await ?;
77
- Ok ( ( ) )
79
+ Ok ( Some ( create_pr ( & gh, & updates) . await ?) )
78
80
}
79
81
80
82
struct Update {
@@ -184,7 +186,7 @@ async fn create_commit(
184
186
Ok ( ( ) )
185
187
}
186
188
187
- async fn create_pr ( gh : & GithubClient , updates : & [ Update ] ) -> Result < ( ) > {
189
+ async fn create_pr ( gh : & GithubClient , updates : & [ Update ] ) -> Result < Issue > {
188
190
let dest_repo = gh. repository ( DEST_REPO ) . await ?;
189
191
let mut body = String :: new ( ) ;
190
192
for update in updates {
@@ -197,5 +199,5 @@ async fn create_pr(gh: &GithubClient, updates: &[Update]) -> Result<()> {
197
199
. new_pr ( gh, TITLE , & head, & dest_repo. default_branch , & body)
198
200
. await ?;
199
201
tracing:: debug!( "created PR {}" , pr. html_url) ;
200
- Ok ( ( ) )
202
+ Ok ( pr )
201
203
}
0 commit comments