@@ -10,8 +10,8 @@ use anyhow::{anyhow, bail};
1010use colored:: Colorize as _;
1111
1212use crate :: git_high_level;
13- use crate :: github_api :: { self , Branch , Remote , RemoteBranch } ;
14- use crate :: utils:: { display_link , with_uuid} ;
13+ use crate :: github :: { self , Branch , Remote , RemoteBranch } ;
14+ use crate :: utils:: { format_pr , format_url , with_uuid} ;
1515use crate :: { commands, confirm_prompt, git} ;
1616
1717/// Backup for a file
@@ -23,7 +23,7 @@ struct FileBackup {
2323}
2424
2525/// Run patchy, if `yes` then there will be no prompt
26- pub async fn run ( yes : bool ) -> anyhow:: Result < ( ) > {
26+ pub async fn run ( yes : bool , use_gh_cli : bool ) -> anyhow:: Result < ( ) > {
2727 let root = config:: ROOT . as_str ( ) ;
2828
2929 let Ok ( config_string) = fs:: read_to_string ( & * config:: FILE_PATH ) else {
@@ -140,7 +140,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
140140 if config. pull_requests . is_empty ( ) && config. branches . is_empty ( ) {
141141 log:: warn!(
142142 "You haven't specified any pull requests or branches to fetch in your config, {}" ,
143- display_link (
143+ format_url (
144144 "see the instructions on how to configure patchy." ,
145145 "https://github.com/nik-rev/patchy?tab=readme-ov-file#config"
146146 )
@@ -157,13 +157,17 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
157157 } in & config. pull_requests
158158 {
159159 // TODO: refactor this to not use such deep nesting
160- let Ok ( ( response, info) ) =
161- github_api:: fetch_pull_request ( & config. repo , * pull_request, None , commit. as_ref ( ) )
162- . await
163- . inspect_err ( |err| {
164- log:: error!( "failed to fetch branch from remote:\n {err}" ) ;
165- } )
166- else {
160+ let Ok ( ( response, info) ) = github:: fetch_pull_request (
161+ & config. repo ,
162+ * pull_request,
163+ None ,
164+ commit. as_ref ( ) ,
165+ use_gh_cli,
166+ )
167+ . await
168+ . inspect_err ( |err| {
169+ log:: error!( "failed to fetch branch from remote:\n {err}" ) ;
170+ } ) else {
167171 continue ;
168172 } ;
169173
@@ -179,16 +183,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
179183
180184 log:: info!(
181185 "Merged pull request {}" ,
182- display_link(
183- & format!(
184- "{}{}{}{}" ,
185- "#" . bright_blue( ) ,
186- pull_request. to_string( ) . bright_blue( ) ,
187- " " . bright_blue( ) ,
188- & response. title. bright_blue( ) . italic( )
189- ) ,
190- & response. html_url
191- ) ,
186+ format_pr( * pull_request, & response. title, & response. html_url) ,
192187 ) ;
193188 }
194189
@@ -197,9 +192,12 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
197192 let owner = & remote. owner ;
198193 let repo = & remote. repo ;
199194 let branch = & remote. branch ;
200- let Ok ( ( _, info) ) = github_api:: fetch_branch ( remote) . await . inspect_err ( |err| {
201- log:: error!( "failed to fetch branch {owner}/{repo}/{branch}: {err}" ) ;
202- } ) else {
195+ let Ok ( ( _, info) ) = github:: fetch_branch ( remote, use_gh_cli)
196+ . await
197+ . inspect_err ( |err| {
198+ log:: error!( "failed to fetch branch {owner}/{repo}/{branch}: {err}" ) ;
199+ } )
200+ else {
203201 continue ;
204202 } ;
205203
0 commit comments