@@ -2025,15 +2025,19 @@ public FormValidation doValidateRepositoryUrlAndCredentials(@CheckForNull @Ances
20252025 StringBuilder sb = new StringBuilder ();
20262026 try {
20272027 GitHub github = Connector .connect (info .getApiUri (), credentials );
2028- if (github .isCredentialValid ()){
2029- sb .append ("Credentials ok." );
2030- }
2028+ try {
2029+ if (github .isCredentialValid ()){
2030+ sb .append ("Credentials ok." );
2031+ }
20312032
2032- GHRepository repo = github .getRepository (info .getRepoOwner () + "/" + info .getRepository ());
2033- if (repo != null ) {
2034- sb .append (" Connected to " );
2035- sb .append (repo .getHtmlUrl ());
2036- sb .append ("." );
2033+ GHRepository repo = github .getRepository (info .getRepoOwner () + "/" + info .getRepository ());
2034+ if (repo != null ) {
2035+ sb .append (" Connected to " );
2036+ sb .append (repo .getHtmlUrl ());
2037+ sb .append ("." );
2038+ }
2039+ } finally {
2040+ Connector .release (github );
20372041 }
20382042 } catch (IOException e ) {
20392043 return FormValidation .error (e , "Error validating repository information. " + sb .toString ());
@@ -2133,12 +2137,16 @@ public ListBoxModel doFillOrganizationItems(@CheckForNull @AncestorInPath Item c
21332137 try {
21342138 StandardCredentials credentials = Connector .lookupScanCredentials (context , apiUri , credentialsId );
21352139 GitHub github = Connector .connect (apiUri , credentials );
2136- if (!github .isAnonymous ()) {
2137- ListBoxModel model = new ListBoxModel ();
2138- for (Map .Entry <String ,GHOrganization > entry : github .getMyOrganizations ().entrySet ()) {
2139- model .add (entry .getKey (), entry .getValue ().getAvatarUrl ());
2140+ try {
2141+ if (!github .isAnonymous ()) {
2142+ ListBoxModel model = new ListBoxModel ();
2143+ for (Map .Entry <String ,GHOrganization > entry : github .getMyOrganizations ().entrySet ()) {
2144+ model .add (entry .getKey (), entry .getValue ().getAvatarUrl ());
2145+ }
2146+ return model ;
21402147 }
2141- return model ;
2148+ } finally {
2149+ Connector .release (github );
21422150 }
21432151 }
21442152 catch (FillErrorResponse e ) {
0 commit comments