private JSONObject getDataFromRestCallPost ( GitHubParsed gitHubParsed , GitHubRepo repo , String password , String personalAccessToken , JSONObject query ) throws MalformedURLException , HygieiaException { ResponseEntity < String > response = makeRestCallPost ( gitHubParsed . getGraphQLUrl ( ) , repo . getUserId ( ) , password , personalAccessToken , query ) ; JSONObject data = ( JSONObject ) parseAsObject ( response ) . get ( "data" ) ; JSONArray errors = getArray ( parseAsObject ( response ) , "errors" ) ; if ( CollectionUtils . isEmpty ( errors ) ) { return data ; } JSONObject error = ( JSONObject ) errors . get ( 0 ) ; if ( ! error . containsKey ( "type" ) || ! error . get ( "type" ) . equals ( "NOT_FOUND" ) ) { throw new HygieiaException ( "Error in GraphQL query:" + errors . toJSONString ( ) , HygieiaException . JSON_FORMAT_ERROR ) ; } RedirectedStatus redirectedStatus = checkForRedirectedRepo ( repo ) ; if ( ! redirectedStatus . isRedirected ( ) ) { throw new HygieiaException ( "Error in GraphQL query:" + errors . toJSONString ( ) , HygieiaException . JSON_FORMAT_ERROR ) ; } String redirectedUrl = redirectedStatus . getRedirectedUrl ( ) ; LOG . debug ( "Repo was redirected from: " + repo . getRepoUrl ( ) + " to " + redirectedUrl ) ; repo . setRepoUrl ( redirectedUrl ) ; gitHubParsed . updateForRedirect ( redirectedUrl ) ; JSONParser parser = new JSONParser ( ) ; try { JSONObject variableJSON = ( JSONObject ) parser . parse ( str ( query , "variables" ) ) ; variableJSON . put ( "name" , gitHubParsed . getRepoName ( ) ) ; variableJSON . put ( "owner" , gitHubParsed . getOrgName ( ) ) ; query . put ( "variables" , variableJSON . toString ( ) ) ; } catch ( ParseException e ) { LOG . error ( "Could not parse JSON String" , e ) ; } return getDataFromRestCallPost ( gitHubParsed , repo , password , personalAccessToken , query ) ; }
Makes use of the graphQL endpoint will not work for REST api