3434import java .io .InputStreamReader ;
3535import java .io .InterruptedIOException ;
3636import java .io .Reader ;
37+ import java .io .UnsupportedEncodingException ;
3738import java .net .URL ;
39+ import java .net .URLEncoder ;
3840import java .util .AbstractSet ;
3941import java .util .ArrayList ;
4042import java .util .Arrays ;
5153import java .util .WeakHashMap ;
5254
5355import static java .util .Arrays .*;
56+ import java .util .logging .Level ;
57+ import java .util .logging .Logger ;
5458import static org .kohsuke .github .Previews .*;
5559
5660/**
@@ -631,6 +635,29 @@ public void delete() throws IOException {
631635 }
632636 }
633637
638+ /**
639+ * Will archive and this repository as read-only. When a repository is archived, any operation
640+ * that can change its state is forbidden. This applies symmetrically if trying to unarchive it.
641+ *
642+ * <p>When you try to do any operation that modifies a read-only repository, it returns the
643+ * response:
644+ *
645+ * <pre>
646+ * org.kohsuke.github.HttpException: {
647+ * "message":"Repository was archived so is read-only.",
648+ * "documentation_url":"https://developer.github.com/v3/repos/#edit"
649+ * }
650+ * </pre>
651+ *
652+ * @throws IOException In case of any networking error or error from the server.
653+ */
654+ public void archive () throws IOException {
655+ edit ("archived" , "true" );
656+ // Generall would not update this record,
657+ // but do so here since this will result in any other update actions failing
658+ archived = true ;
659+ }
660+
634661 /**
635662 * Sort orders for listing forks
636663 */
@@ -1049,12 +1076,10 @@ protected void wrapUp(GHCommitComment[] page) {
10491076 /**
10501077 * Gets the basic license details for the repository.
10511078 * <p>
1052- * This is a preview item and subject to change.
10531079 *
10541080 * @throws IOException as usual but also if you don't use the preview connector
10551081 * @return null if there's no license.
10561082 */
1057- @ Preview @ Deprecated
10581083 public GHLicense getLicense () throws IOException {
10591084 GHContentWithLicense lic = getLicenseContent_ ();
10601085 return lic !=null ? lic .license : null ;
@@ -1063,21 +1088,17 @@ public GHLicense getLicense() throws IOException{
10631088 /**
10641089 * Retrieves the contents of the repository's license file - makes an additional API call
10651090 * <p>
1066- * This is a preview item and subject to change.
10671091 *
10681092 * @return details regarding the license contents, or null if there's no license.
10691093 * @throws IOException as usual but also if you don't use the preview connector
10701094 */
1071- @ Preview @ Deprecated
10721095 public GHContent getLicenseContent () throws IOException {
10731096 return getLicenseContent_ ();
10741097 }
10751098
1076- @ Preview @ Deprecated
10771099 private GHContentWithLicense getLicenseContent_ () throws IOException {
10781100 try {
10791101 return root .retrieve ()
1080- .withPreview (DRAX )
10811102 .to (getApiTailUrl ("license" ), GHContentWithLicense .class ).wrap (this );
10821103 } catch (FileNotFoundException e ) {
10831104 return null ;
@@ -1376,8 +1397,25 @@ public Map<String,GHBranch> getBranches() throws IOException {
13761397 return r ;
13771398 }
13781399
1400+ /**
1401+ * Replace special characters (e.g. #) with standard values (e.g. %23) so
1402+ * GitHub understands what is being requested.
1403+ * @param The string to be encoded.
1404+ * @return The encoded string.
1405+ */
1406+ private String UrlEncode (String value ) {
1407+ try {
1408+ return URLEncoder .encode (value , org .apache .commons .codec .CharEncoding .UTF_8 );
1409+ } catch (UnsupportedEncodingException ex ) {
1410+ Logger .getLogger (GHRepository .class .getName ()).log (Level .SEVERE , null , ex );
1411+ }
1412+
1413+ // Something went wrong - just return original value as is.
1414+ return value ;
1415+ }
1416+
13791417 public GHBranch getBranch (String name ) throws IOException {
1380- return root .retrieve ().to (getApiTailUrl ("branches/" +name ),GHBranch .class ).wrap (this );
1418+ return root .retrieve ().to (getApiTailUrl ("branches/" +UrlEncode ( name ) ),GHBranch .class ).wrap (this );
13811419 }
13821420
13831421 /**
0 commit comments