@@ -205,6 +205,24 @@ nest! {
205205 }
206206}
207207
208+ #[ derive( Serialize , Clone ) ]
209+ #[ serde( rename_all = "camelCase" ) ]
210+ pub struct GetRepositoryVars {
211+ pub owner : String ,
212+ pub name : String ,
213+ pub provider : RepositoryProvider ,
214+ }
215+
216+ nest ! {
217+ #[ derive( Debug , Deserialize , Serialize ) ] *
218+ #[ serde( rename_all = "camelCase" ) ] *
219+ struct GetRepositoryData {
220+ repository: Option <pub struct GetRepositoryPayload {
221+ pub id: String ,
222+ } >
223+ }
224+ }
225+
208226impl CodSpeedAPIClient {
209227 pub async fn create_login_session ( & self ) -> Result < CreateLoginSessionPayload > {
210228 let response = self
@@ -281,6 +299,31 @@ impl CodSpeedAPIClient {
281299 Err ( err) => bail ! ( "Failed to get or create project repository: {err}" ) ,
282300 }
283301 }
302+
303+ /// Check if a repository exists in CodSpeed.
304+ /// Returns Some(payload) if the repository exists, None otherwise.
305+ pub async fn get_repository (
306+ & self ,
307+ vars : GetRepositoryVars ,
308+ ) -> Result < Option < GetRepositoryPayload > > {
309+ let response = self
310+ . gql_client
311+ . query_with_vars_unwrap :: < GetRepositoryData , GetRepositoryVars > (
312+ include_str ! ( "queries/GetRepository.gql" ) ,
313+ vars. clone ( ) ,
314+ )
315+ . await ;
316+ match response {
317+ Ok ( response) => Ok ( response. repository ) ,
318+ Err ( err) if err. contains_error_code ( "REPOSITORY_NOT_FOUND" ) => Ok ( None ) ,
319+ Err ( err) if err. contains_error_code ( "UNAUTHENTICATED" ) => {
320+ bail ! ( "Your session has expired, please login again using `codspeed auth login`" )
321+ }
322+ Err ( err) => {
323+ bail ! ( "Failed to get repository: {err}" )
324+ }
325+ }
326+ }
284327}
285328
286329impl CodSpeedAPIClient {
0 commit comments