44
44
import com .spotify .github .v3 .repos .CommitStatus ;
45
45
import com .spotify .github .v3 .repos .CommitWithFolderContent ;
46
46
import 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 .*;
49
48
import com .spotify .github .v3 .repos .FolderContent ;
50
49
import com .spotify .github .v3 .repos .Languages ;
51
50
import com .spotify .github .v3 .repos .Repository ;
52
51
import com .spotify .github .v3 .repos .RepositoryInvitation ;
53
52
import 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
+
56
54
import java .io .InputStream ;
57
55
import java .lang .invoke .MethodHandles ;
58
56
import java .util .Iterator ;
@@ -79,7 +77,8 @@ public class RepositoryClient {
79
77
public static final String STATUS_URI_TEMPLATE = "/repos/%s/%s/statuses/%s" ;
80
78
private static final String COMMITS_URI_TEMPLATE = "/repos/%s/%s/commits" ;
81
79
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" ;
83
82
private static final String COMMIT_STATUS_URI_TEMPLATE = "/repos/%s/%s/commits/%s/status" ;
84
83
private static final String TREE_SHA_URI_TEMPLATE = "/repos/%s/%s/git/trees/%s" ;
85
84
private static final String COMPARE_COMMIT_TEMPLATE = "/repos/%s/%s/compare/%s...%s" ;
@@ -160,6 +159,18 @@ public CompletableFuture<Repository> getRepository() {
160
159
return github .request (path , Repository .class );
161
160
}
162
161
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
+
163
174
/**
164
175
* List all repositories in this organization.
165
176
*
@@ -199,13 +210,13 @@ public CompletableFuture<Boolean> isCollaborator(final String user) {
199
210
/**
200
211
* Add a collaborator to the repo.
201
212
*
202
- * @param user the GitHub username to add
213
+ * @param user the GitHub username to add
203
214
* @param permission the permission level for the user; one of RepositoryPermission, or a custom
204
- * role
215
+ * role
205
216
* @return
206
217
*/
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 ) {
209
220
final String path = String .format (REPOSITORY_COLLABORATOR , owner , repo , user );
210
221
final String data = github .json ().toJsonUnchecked (Map .of ("permission" , permission ));
211
222
return github
@@ -216,12 +227,12 @@ public CompletableFuture<Optional<RepositoryInvitation>> addCollaborator(final S
216
227
// not called.
217
228
if (response .code () == NO_CONTENT ) {
218
229
/*
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
+ */
225
236
return Optional .empty ();
226
237
}
227
238
final RepositoryInvitation invitation =
@@ -284,18 +295,22 @@ public CompletableFuture<Optional<InputStream>> downloadZipball(final String ref
284
295
return downloadRepository (REPOSITORY_DOWNLOAD_ZIPBALL , Optional .of (ref ));
285
296
}
286
297
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 ) {
288
300
final var repoRef = maybeRef .orElse ("" );
289
301
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 ();
292
307
293
- if (body == null ) {
294
- return Optional .empty ();
295
- }
308
+ if (body == null ) {
309
+ return Optional .empty ();
310
+ }
296
311
297
- return Optional .of (body .byteStream ());
298
- });
312
+ return Optional .of (body .byteStream ());
313
+ });
299
314
}
300
315
301
316
/**
@@ -457,7 +472,8 @@ public CompletableFuture<Content> getFileContent(final String path, final String
457
472
* @param request file creation request
458
473
* @return commit with content
459
474
*/
460
- public CompletableFuture <CommitWithFolderContent > createFileContent (final String path , final FileCreate request ) {
475
+ public CompletableFuture <CommitWithFolderContent > createFileContent (
476
+ final String path , final FileCreate request ) {
461
477
final String contentPath = getContentPath (path , "" );
462
478
final String requestBody = github .json ().toJsonUnchecked (request );
463
479
return github .put (contentPath , requestBody , CommitWithFolderContent .class );
@@ -470,7 +486,8 @@ public CompletableFuture<CommitWithFolderContent> createFileContent(final String
470
486
* @param request file update request
471
487
* @return commit with content
472
488
*/
473
- public CompletableFuture <CommitWithFolderContent > updateFileContent (final String path , final FileUpdate request ) {
489
+ public CompletableFuture <CommitWithFolderContent > updateFileContent (
490
+ final String path , final FileUpdate request ) {
474
491
final String contentPath = getContentPath (path , "" );
475
492
final String requestBody = github .json ().toJsonUnchecked (request );
476
493
return github .put (contentPath , requestBody , CommitWithFolderContent .class );
@@ -546,9 +563,8 @@ public CompletableFuture<Branch> getBranch(final String branch) {
546
563
}
547
564
548
565
/**
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.
552
568
*
553
569
* @return list of 30 branches in repository
554
570
*/
@@ -557,7 +573,7 @@ public CompletableFuture<List<Branch>> listBranches() {
557
573
return github .request (path , LIST_BRANCHES );
558
574
}
559
575
560
- /**
576
+ /**
561
577
* List all branches in repository
562
578
*
563
579
* @return list of all branches in repository
@@ -567,7 +583,6 @@ public Iterator<AsyncPage<Branch>> listAllBranches() {
567
583
return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_BRANCHES ));
568
584
}
569
585
570
-
571
586
/**
572
587
* Delete a comment for a given id.
573
588
*
0 commit comments