4444import com .spotify .github .v3 .repos .CommitStatus ;
4545import com .spotify .github .v3 .repos .CommitWithFolderContent ;
4646import com .spotify .github .v3 .repos .Content ;
47- import com .spotify .github .v3 .repos .requests .FileCreate ;
48- import com .spotify .github .v3 .repos .requests .FileUpdate ;
47+ import com .spotify .github .v3 .repos .requests .*;
4948import com .spotify .github .v3 .repos .FolderContent ;
5049import com .spotify .github .v3 .repos .Languages ;
5150import com .spotify .github .v3 .repos .Repository ;
5251import com .spotify .github .v3 .repos .RepositoryInvitation ;
5352import com .spotify .github .v3 .repos .Status ;
54- import com .spotify .github .v3 .repos .requests .AuthenticatedUserRepositoriesFilter ;
55- import com .spotify .github .v3 .repos .requests .RepositoryCreateStatus ;
53+
5654import java .io .InputStream ;
5755import java .lang .invoke .MethodHandles ;
5856import java .util .Iterator ;
@@ -79,7 +77,8 @@ public class RepositoryClient {
7977 public static final String STATUS_URI_TEMPLATE = "/repos/%s/%s/statuses/%s" ;
8078 private static final String COMMITS_URI_TEMPLATE = "/repos/%s/%s/commits" ;
8179 private static final String COMMIT_SHA_URI_TEMPLATE = "/repos/%s/%s/commits/%s" ;
82- private static final String COMMIT_PULL_REQUESTS_SHA_URI_TEMPLATE = "/repos/%s/%s/commits/%s/pulls" ;
80+ private static final String COMMIT_PULL_REQUESTS_SHA_URI_TEMPLATE =
81+ "/repos/%s/%s/commits/%s/pulls" ;
8382 private static final String COMMIT_STATUS_URI_TEMPLATE = "/repos/%s/%s/commits/%s/status" ;
8483 private static final String TREE_SHA_URI_TEMPLATE = "/repos/%s/%s/git/trees/%s" ;
8584 private static final String COMPARE_COMMIT_TEMPLATE = "/repos/%s/%s/compare/%s...%s" ;
@@ -160,6 +159,18 @@ public CompletableFuture<Repository> getRepository() {
160159 return github .request (path , Repository .class );
161160 }
162161
162+ /**
163+ * Update Repository properties
164+ * https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#update-a-repository
165+ *
166+ * @return repository information
167+ */
168+ public CompletableFuture <Repository > updateRepository (final RepositoryUpdate repoUpdate ) {
169+ final String path = String .format (REPOSITORY_URI_TEMPLATE , owner , repo );
170+ final String data = github .json ().toJsonUnchecked (repoUpdate );
171+ return github .patch (path , data , Repository .class );
172+ }
173+
163174 /**
164175 * List all repositories in this organization.
165176 *
@@ -199,13 +210,13 @@ public CompletableFuture<Boolean> isCollaborator(final String user) {
199210 /**
200211 * Add a collaborator to the repo.
201212 *
202- * @param user the GitHub username to add
213+ * @param user the GitHub username to add
203214 * @param permission the permission level for the user; one of RepositoryPermission, or a custom
204- * role
215+ * role
205216 * @return
206217 */
207- public CompletableFuture <Optional <RepositoryInvitation >> addCollaborator (final String user ,
208- final String permission ) {
218+ public CompletableFuture <Optional <RepositoryInvitation >> addCollaborator (
219+ final String user , final String permission ) {
209220 final String path = String .format (REPOSITORY_COLLABORATOR , owner , repo , user );
210221 final String data = github .json ().toJsonUnchecked (Map .of ("permission" , permission ));
211222 return github
@@ -216,12 +227,12 @@ public CompletableFuture<Optional<RepositoryInvitation>> addCollaborator(final S
216227 // not called.
217228 if (response .code () == NO_CONTENT ) {
218229 /*
219- GitHub returns a 204 when:
220- - an existing collaborator is added as a collaborator
221- - an organization member is added as an individual collaborator
222- - an existing team member (whose team is also a repository collaborator) is
223- added as a collaborator
224- */
230+ GitHub returns a 204 when:
231+ - an existing collaborator is added as a collaborator
232+ - an organization member is added as an individual collaborator
233+ - an existing team member (whose team is also a repository collaborator) is
234+ added as a collaborator
235+ */
225236 return Optional .empty ();
226237 }
227238 final RepositoryInvitation invitation =
@@ -284,18 +295,22 @@ public CompletableFuture<Optional<InputStream>> downloadZipball(final String ref
284295 return downloadRepository (REPOSITORY_DOWNLOAD_ZIPBALL , Optional .of (ref ));
285296 }
286297
287- private CompletableFuture <Optional <InputStream >> downloadRepository (final String path , final Optional <String > maybeRef ) {
298+ private CompletableFuture <Optional <InputStream >> downloadRepository (
299+ final String path , final Optional <String > maybeRef ) {
288300 final var repoRef = maybeRef .orElse ("" );
289301 final var repoPath = String .format (path , owner , repo , repoRef );
290- return github .request (repoPath ).thenApply (response -> {
291- var body = response .body ();
302+ return github
303+ .request (repoPath )
304+ .thenApply (
305+ response -> {
306+ var body = response .body ();
292307
293- if (body == null ) {
294- return Optional .empty ();
295- }
308+ if (body == null ) {
309+ return Optional .empty ();
310+ }
296311
297- return Optional .of (body .byteStream ());
298- });
312+ return Optional .of (body .byteStream ());
313+ });
299314 }
300315
301316 /**
@@ -457,7 +472,8 @@ public CompletableFuture<Content> getFileContent(final String path, final String
457472 * @param request file creation request
458473 * @return commit with content
459474 */
460- public CompletableFuture <CommitWithFolderContent > createFileContent (final String path , final FileCreate request ) {
475+ public CompletableFuture <CommitWithFolderContent > createFileContent (
476+ final String path , final FileCreate request ) {
461477 final String contentPath = getContentPath (path , "" );
462478 final String requestBody = github .json ().toJsonUnchecked (request );
463479 return github .put (contentPath , requestBody , CommitWithFolderContent .class );
@@ -470,7 +486,8 @@ public CompletableFuture<CommitWithFolderContent> createFileContent(final String
470486 * @param request file update request
471487 * @return commit with content
472488 */
473- public CompletableFuture <CommitWithFolderContent > updateFileContent (final String path , final FileUpdate request ) {
489+ public CompletableFuture <CommitWithFolderContent > updateFileContent (
490+ final String path , final FileUpdate request ) {
474491 final String contentPath = getContentPath (path , "" );
475492 final String requestBody = github .json ().toJsonUnchecked (request );
476493 return github .put (contentPath , requestBody , CommitWithFolderContent .class );
@@ -546,9 +563,8 @@ public CompletableFuture<Branch> getBranch(final String branch) {
546563 }
547564
548565 /**
549- * List some branches in repository.
550- * Doesn't return more than 30 branches.
551- * Use {@link RepositoryClient#listAllBranches} instead to get all branches.
566+ * List some branches in repository. Doesn't return more than 30 branches. Use {@link
567+ * RepositoryClient#listAllBranches} instead to get all branches.
552568 *
553569 * @return list of 30 branches in repository
554570 */
@@ -557,7 +573,7 @@ public CompletableFuture<List<Branch>> listBranches() {
557573 return github .request (path , LIST_BRANCHES );
558574 }
559575
560- /**
576+ /**
561577 * List all branches in repository
562578 *
563579 * @return list of all branches in repository
@@ -567,7 +583,6 @@ public Iterator<AsyncPage<Branch>> listAllBranches() {
567583 return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_BRANCHES ));
568584 }
569585
570-
571586 /**
572587 * Delete a comment for a given id.
573588 *
0 commit comments