Skip to content

Commit 0dfbca1

Browse files
committed
Merge remote-tracking branch 'origin/main' into 6.x
# Conflicts: # src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
2 parents 184fd89 + b563bb1 commit 0dfbca1

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed

src/main/java/org/gitlab4j/api/GroupApi.java

+80
Original file line numberDiff line numberDiff line change
@@ -2438,4 +2438,84 @@ public GroupHook addWebhook(Object groupIdOrPath, GroupHookParams groupHookParam
24382438
Response.Status.CREATED, groupHookParams.getForm(), "groups", getGroupIdOrPath(groupIdOrPath), "hooks");
24392439
return (response.readEntity(GroupHook.class));
24402440
}
2441+
2442+
/**
2443+
* Get all uploads of the group sorted by created_at in descending order.
2444+
*
2445+
* You must have at least the Maintainer role to use this endpoint.
2446+
*
2447+
* <pre><code>GitLab Endpoint: GET /groups/:id/uploads</code></pre>
2448+
*
2449+
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance, required
2450+
* @return list of uploaded files
2451+
* @throws GitLabApiException if any exception occurs
2452+
*/
2453+
public List<UploadedFile> getUploadFiles(Object groupIdOrPath) throws GitLabApiException {
2454+
Response response = get(Response.Status.OK, null, "projects", getGroupIdOrPath(groupIdOrPath), "uploads");
2455+
return (response.readEntity(new GenericType<List<UploadedFile>>() {}));
2456+
}
2457+
2458+
/**
2459+
* Uploads a file to the specified group to be used in an issue or merge request description, or a comment.
2460+
*
2461+
* <pre><code>GitLab Endpoint: POST /groups/:id/uploads</code></pre>
2462+
*
2463+
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance, required
2464+
* @param fileToUpload the File instance of the file to upload, required
2465+
* @return a FileUpload instance with information on the just uploaded file
2466+
* @throws GitLabApiException if any exception occurs
2467+
*/
2468+
public FileUpload uploadFile(Object groupIdOrPath, File fileToUpload) throws GitLabApiException {
2469+
return (uploadFile(groupIdOrPath, fileToUpload, null));
2470+
}
2471+
2472+
/**
2473+
* Uploads a file to the specified group to be used in an issue or merge request description, or a comment.
2474+
*
2475+
* <pre><code>GitLab Endpoint: POST /groups/:id/uploads</code></pre>
2476+
*
2477+
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance, required
2478+
* @param fileToUpload the File instance of the file to upload, required
2479+
* @param mediaType unused; will be removed in the next major version
2480+
* @return a FileUpload instance with information on the just uploaded file
2481+
* @throws GitLabApiException if any exception occurs
2482+
*/
2483+
public FileUpload uploadFile(Object groupIdOrPath, File fileToUpload, String mediaType) throws GitLabApiException {
2484+
Response response = upload(
2485+
Response.Status.CREATED,
2486+
"file",
2487+
fileToUpload,
2488+
mediaType,
2489+
"groups",
2490+
getGroupIdOrPath(groupIdOrPath),
2491+
"uploads");
2492+
return (response.readEntity(FileUpload.class));
2493+
}
2494+
2495+
/**
2496+
* Uploads some data in an {@link InputStream} to the specified group,
2497+
* to be used in an issue or merge request description, or a comment.
2498+
*
2499+
* <pre><code>GitLab Endpoint: POST /groups/:id/uploads</code></pre>
2500+
*
2501+
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance, required
2502+
* @param inputStream the data to upload, required
2503+
* @param filename The filename of the file to upload
2504+
* @param mediaType unused; will be removed in the next major version
2505+
* @return a FileUpload instance with information on the just uploaded file
2506+
* @throws GitLabApiException if any exception occurs
2507+
*/
2508+
public FileUpload uploadFile(Object groupIdOrPath, InputStream inputStream, String filename, String mediaType)
2509+
throws GitLabApiException {
2510+
Response response = upload(
2511+
Response.Status.CREATED,
2512+
"file",
2513+
inputStream,
2514+
filename,
2515+
mediaType,
2516+
"groups",
2517+
getGroupIdOrPath(groupIdOrPath),
2518+
"uploads");
2519+
return (response.readEntity(FileUpload.class));
2520+
}
24412521
}

src/main/java/org/gitlab4j/api/ProjectApi.java

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.gitlab4j.api.models.PushRules;
6868
import org.gitlab4j.api.models.RemoteMirror;
6969
import org.gitlab4j.api.models.Snippet;
70+
import org.gitlab4j.api.models.UploadedFile;
7071
import org.gitlab4j.api.models.Variable;
7172
import org.gitlab4j.api.models.Visibility;
7273
import org.gitlab4j.api.utils.ISO8601;
@@ -3040,6 +3041,22 @@ public Project unarchiveProject(Object projectIdOrPath) throws GitLabApiExceptio
30403041
return (response.readEntity(Project.class));
30413042
}
30423043

3044+
/**
3045+
* Get all uploads of the project sorted by created_at in descending order.
3046+
*
3047+
* You must have at least the Maintainer role to use this endpoint.
3048+
*
3049+
* <pre><code>GitLab Endpoint: GET /groups/:id/uploads</code></pre>
3050+
*
3051+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
3052+
* @return list of uploaded files
3053+
* @throws GitLabApiException if any exception occurs
3054+
*/
3055+
public List<UploadedFile> getUploadFiles(Object projectIdOrPath) throws GitLabApiException {
3056+
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "uploads");
3057+
return (response.readEntity(new GenericType<List<UploadedFile>>() {}));
3058+
}
3059+
30433060
/**
30443061
* Uploads a file to the specified project to be used in an issue or merge request description, or a comment.
30453062
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
5+
import org.gitlab4j.api.utils.JacksonJson;
6+
7+
public class UploadedByUser implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
10+
private Long id;
11+
private String username;
12+
private String name;
13+
14+
public Long getId() {
15+
return id;
16+
}
17+
18+
public void setId(Long id) {
19+
this.id = id;
20+
}
21+
22+
public String getUsername() {
23+
return username;
24+
}
25+
26+
public void setUsername(String username) {
27+
this.username = username;
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return (JacksonJson.toJsonString(this));
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
import java.util.Date;
5+
6+
import org.gitlab4j.api.utils.JacksonJson;
7+
8+
public class UploadedFile implements Serializable {
9+
private static final long serialVersionUID = 1L;
10+
11+
private Long id;
12+
private Long size;
13+
private String filename;
14+
private Date createdAt;
15+
private UploadedByUser uploadedBy;
16+
17+
public Long getId() {
18+
return id;
19+
}
20+
21+
public void setId(Long id) {
22+
this.id = id;
23+
}
24+
25+
public Long getSize() {
26+
return size;
27+
}
28+
29+
public void setSize(Long size) {
30+
this.size = size;
31+
}
32+
33+
public String getFilename() {
34+
return filename;
35+
}
36+
37+
public void setFilename(String filename) {
38+
this.filename = filename;
39+
}
40+
41+
public Date getCreatedAt() {
42+
return createdAt;
43+
}
44+
45+
public void setCreatedAt(Date createdAt) {
46+
this.createdAt = createdAt;
47+
}
48+
49+
public UploadedByUser getUploadedBy() {
50+
return uploadedBy;
51+
}
52+
53+
public void setUploadedBy(UploadedByUser uploadedBy) {
54+
this.uploadedBy = uploadedBy;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return (JacksonJson.toJsonString(this));
60+
}
61+
}

src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.List;
3434
import java.util.Map;
3535

36+
import org.gitlab4j.api.models.*;
3637
import org.gitlab4j.api.models.AccessRequest;
3738
import org.gitlab4j.api.models.Application;
3839
import org.gitlab4j.api.models.ApplicationSettings;
@@ -810,6 +811,12 @@ public void testUser() throws Exception {
810811
assertTrue(compareJson(user, "user.json"));
811812
}
812813

814+
@Test
815+
public void testUploadedFile() throws Exception {
816+
UploadedFile uploadedFile = unmarshalResource(UploadedFile.class, "uploaded-file.json");
817+
assertTrue(compareJson(uploadedFile, "uploaded-file.json"));
818+
}
819+
813820
@Test
814821
public void testImpersonationToken() throws Exception {
815822
ImpersonationToken token = unmarshalResource(ImpersonationToken.class, "impersonation-token.json");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": 1623,
3+
"size": 435,
4+
"filename": "some-feature.png",
5+
"created_at": "2024-09-23T13:52:15Z",
6+
"uploaded_by": {
7+
"id": 54,
8+
"username": "john.smith",
9+
"name": "John Smith"
10+
}
11+
}

0 commit comments

Comments
 (0)