@@ -218,6 +218,24 @@ nest! {
218218 }
219219}
220220
221+ #[ derive( Serialize , Clone ) ]
222+ #[ serde( rename_all = "camelCase" ) ]
223+ pub struct GetRepositoryVars {
224+ pub owner : String ,
225+ pub name : String ,
226+ pub provider : RepositoryProvider ,
227+ }
228+
229+ nest ! {
230+ #[ derive( Debug , Deserialize , Serialize ) ] *
231+ #[ serde( rename_all = "camelCase" ) ] *
232+ struct GetRepositoryData {
233+ repository: Option <pub struct GetRepositoryPayload {
234+ pub id: String ,
235+ } >
236+ }
237+ }
238+
221239impl CodSpeedAPIClient {
222240 pub async fn create_login_session ( & self ) -> Result < CreateLoginSessionPayload > {
223241 let response = self
@@ -294,6 +312,31 @@ impl CodSpeedAPIClient {
294312 Err ( err) => bail ! ( "Failed to get or create project repository: {err}" ) ,
295313 }
296314 }
315+
316+ /// Check if a repository exists in CodSpeed.
317+ /// Returns Some(payload) if the repository exists, None otherwise.
318+ pub async fn get_repository (
319+ & self ,
320+ vars : GetRepositoryVars ,
321+ ) -> Result < Option < GetRepositoryPayload > > {
322+ let response = self
323+ . gql_client
324+ . query_with_vars_unwrap :: < GetRepositoryData , GetRepositoryVars > (
325+ include_str ! ( "queries/GetRepository.gql" ) ,
326+ vars. clone ( ) ,
327+ )
328+ . await ;
329+ match response {
330+ Ok ( response) => Ok ( response. repository ) ,
331+ Err ( err) if err. contains_error_code ( "REPOSITORY_NOT_FOUND" ) => Ok ( None ) ,
332+ Err ( err) if err. contains_error_code ( "UNAUTHENTICATED" ) => {
333+ bail ! ( "Your session has expired, please login again using `codspeed auth login`" )
334+ }
335+ Err ( err) => {
336+ bail ! ( "Failed to get repository: {err}" )
337+ }
338+ }
339+ }
297340}
298341
299342impl CodSpeedAPIClient {
0 commit comments