diff --git a/src/main/java/org/gitlab4j/api/GroupApi.java b/src/main/java/org/gitlab4j/api/GroupApi.java
index 3d5c7db9..fe5a022b 100644
--- a/src/main/java/org/gitlab4j/api/GroupApi.java
+++ b/src/main/java/org/gitlab4j/api/GroupApi.java
@@ -2438,4 +2438,84 @@ public GroupHook addWebhook(Object groupIdOrPath, GroupHookParams groupHookParam
Response.Status.CREATED, groupHookParams.getForm(), "groups", getGroupIdOrPath(groupIdOrPath), "hooks");
return (response.readEntity(GroupHook.class));
}
+
+ /**
+ * Get all uploads of the group sorted by created_at in descending order.
+ *
+ * You must have at least the Maintainer role to use this endpoint.
+ *
+ *
GitLab Endpoint: GET /groups/:id/uploads
+ *
+ * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance, required
+ * @return list of uploaded files
+ * @throws GitLabApiException if any exception occurs
+ */
+ public List getUploadFiles(Object groupIdOrPath) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "projects", getGroupIdOrPath(groupIdOrPath), "uploads");
+ return (response.readEntity(new GenericType>() {}));
+ }
+
+ /**
+ * Uploads a file to the specified group to be used in an issue or merge request description, or a comment.
+ *
+ * GitLab Endpoint: POST /groups/:id/uploads
+ *
+ * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance, required
+ * @param fileToUpload the File instance of the file to upload, required
+ * @return a FileUpload instance with information on the just uploaded file
+ * @throws GitLabApiException if any exception occurs
+ */
+ public FileUpload uploadFile(Object groupIdOrPath, File fileToUpload) throws GitLabApiException {
+ return (uploadFile(groupIdOrPath, fileToUpload, null));
+ }
+
+ /**
+ * Uploads a file to the specified group to be used in an issue or merge request description, or a comment.
+ *
+ * GitLab Endpoint: POST /groups/:id/uploads
+ *
+ * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance, required
+ * @param fileToUpload the File instance of the file to upload, required
+ * @param mediaType unused; will be removed in the next major version
+ * @return a FileUpload instance with information on the just uploaded file
+ * @throws GitLabApiException if any exception occurs
+ */
+ public FileUpload uploadFile(Object groupIdOrPath, File fileToUpload, String mediaType) throws GitLabApiException {
+ Response response = upload(
+ Response.Status.CREATED,
+ "file",
+ fileToUpload,
+ mediaType,
+ "groups",
+ getGroupIdOrPath(groupIdOrPath),
+ "uploads");
+ return (response.readEntity(FileUpload.class));
+ }
+
+ /**
+ * Uploads some data in an {@link InputStream} to the specified group,
+ * to be used in an issue or merge request description, or a comment.
+ *
+ * GitLab Endpoint: POST /groups/:id/uploads
+ *
+ * @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance, required
+ * @param inputStream the data to upload, required
+ * @param filename The filename of the file to upload
+ * @param mediaType unused; will be removed in the next major version
+ * @return a FileUpload instance with information on the just uploaded file
+ * @throws GitLabApiException if any exception occurs
+ */
+ public FileUpload uploadFile(Object groupIdOrPath, InputStream inputStream, String filename, String mediaType)
+ throws GitLabApiException {
+ Response response = upload(
+ Response.Status.CREATED,
+ "file",
+ inputStream,
+ filename,
+ mediaType,
+ "groups",
+ getGroupIdOrPath(groupIdOrPath),
+ "uploads");
+ return (response.readEntity(FileUpload.class));
+ }
}
diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java
index e97e91ca..b77318c1 100644
--- a/src/main/java/org/gitlab4j/api/ProjectApi.java
+++ b/src/main/java/org/gitlab4j/api/ProjectApi.java
@@ -67,6 +67,7 @@
import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.RemoteMirror;
import org.gitlab4j.api.models.Snippet;
+import org.gitlab4j.api.models.UploadedFile;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
import org.gitlab4j.api.utils.ISO8601;
@@ -3040,6 +3041,22 @@ public Project unarchiveProject(Object projectIdOrPath) throws GitLabApiExceptio
return (response.readEntity(Project.class));
}
+ /**
+ * Get all uploads of the project sorted by created_at in descending order.
+ *
+ * You must have at least the Maintainer role to use this endpoint.
+ *
+ * GitLab Endpoint: GET /groups/:id/uploads
+ *
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
+ * @return list of uploaded files
+ * @throws GitLabApiException if any exception occurs
+ */
+ public List getUploadFiles(Object projectIdOrPath) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "uploads");
+ return (response.readEntity(new GenericType>() {}));
+ }
+
/**
* Uploads a file to the specified project to be used in an issue or merge request description, or a comment.
*
diff --git a/src/main/java/org/gitlab4j/api/models/UploadedByUser.java b/src/main/java/org/gitlab4j/api/models/UploadedByUser.java
new file mode 100644
index 00000000..5e641ca2
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/UploadedByUser.java
@@ -0,0 +1,42 @@
+package org.gitlab4j.api.models;
+
+import java.io.Serializable;
+
+import org.gitlab4j.api.utils.JacksonJson;
+
+public class UploadedByUser implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private Long id;
+ private String username;
+ private String name;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+}
diff --git a/src/main/java/org/gitlab4j/api/models/UploadedFile.java b/src/main/java/org/gitlab4j/api/models/UploadedFile.java
new file mode 100644
index 00000000..9960d1aa
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/UploadedFile.java
@@ -0,0 +1,61 @@
+package org.gitlab4j.api.models;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.gitlab4j.api.utils.JacksonJson;
+
+public class UploadedFile implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private Long id;
+ private Long size;
+ private String filename;
+ private Date createdAt;
+ private UploadedByUser uploadedBy;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getSize() {
+ return size;
+ }
+
+ public void setSize(Long size) {
+ this.size = size;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+
+ public void setFilename(String filename) {
+ this.filename = filename;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ public UploadedByUser getUploadedBy() {
+ return uploadedBy;
+ }
+
+ public void setUploadedBy(UploadedByUser uploadedBy) {
+ this.uploadedBy = uploadedBy;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+}
diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
index 831336e1..2df8a0e6 100644
--- a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
+++ b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
@@ -33,106 +33,8 @@
import java.util.List;
import java.util.Map;
-import org.gitlab4j.api.models.AccessRequest;
-import org.gitlab4j.api.models.Application;
-import org.gitlab4j.api.models.ApplicationSettings;
-import org.gitlab4j.api.models.ApprovalRule;
-import org.gitlab4j.api.models.ApprovalState;
-import org.gitlab4j.api.models.ArtifactsFile;
-import org.gitlab4j.api.models.AuditEvent;
-import org.gitlab4j.api.models.AwardEmoji;
-import org.gitlab4j.api.models.Badge;
-import org.gitlab4j.api.models.Blame;
-import org.gitlab4j.api.models.Board;
-import org.gitlab4j.api.models.Branch;
-import org.gitlab4j.api.models.Bridge;
-import org.gitlab4j.api.models.ChildEpic;
-import org.gitlab4j.api.models.Comment;
-import org.gitlab4j.api.models.Commit;
-import org.gitlab4j.api.models.CommitPayload;
-import org.gitlab4j.api.models.CommitStatus;
-import org.gitlab4j.api.models.CompareResults;
-import org.gitlab4j.api.models.Contributor;
-import org.gitlab4j.api.models.CreatedChildEpic;
-import org.gitlab4j.api.models.DeployKey;
-import org.gitlab4j.api.models.DeployToken;
-import org.gitlab4j.api.models.Deployment;
-import org.gitlab4j.api.models.Diff;
-import org.gitlab4j.api.models.Discussion;
-import org.gitlab4j.api.models.Email;
-import org.gitlab4j.api.models.Environment;
-import org.gitlab4j.api.models.Epic;
-import org.gitlab4j.api.models.EpicIssue;
-import org.gitlab4j.api.models.EpicIssueLink;
-import org.gitlab4j.api.models.Event;
-import org.gitlab4j.api.models.ExportStatus;
-import org.gitlab4j.api.models.ExternalStatusCheck;
-import org.gitlab4j.api.models.ExternalStatusCheckResult;
-import org.gitlab4j.api.models.ExternalStatusCheckStatus;
-import org.gitlab4j.api.models.FileUpload;
-import org.gitlab4j.api.models.GitLabCiTemplate;
-import org.gitlab4j.api.models.GitLabCiTemplateElement;
-import org.gitlab4j.api.models.GpgSignature;
-import org.gitlab4j.api.models.Group;
-import org.gitlab4j.api.models.GroupAccessToken;
-import org.gitlab4j.api.models.GroupHook;
-import org.gitlab4j.api.models.HealthCheckInfo;
-import org.gitlab4j.api.models.ImpersonationToken;
-import org.gitlab4j.api.models.ImportStatus;
-import org.gitlab4j.api.models.Issue;
-import org.gitlab4j.api.models.IssueLink;
-import org.gitlab4j.api.models.IssuesStatistics;
-import org.gitlab4j.api.models.Iteration;
-import org.gitlab4j.api.models.Job;
-import org.gitlab4j.api.models.Key;
-import org.gitlab4j.api.models.Label;
-import org.gitlab4j.api.models.LabelEvent;
-import org.gitlab4j.api.models.LdapGroupLink;
-import org.gitlab4j.api.models.Link;
-import org.gitlab4j.api.models.Member;
-import org.gitlab4j.api.models.MergeRequest;
-import org.gitlab4j.api.models.MergeRequestDiff;
-import org.gitlab4j.api.models.MergeRequestVersion;
-import org.gitlab4j.api.models.Metadata;
-import org.gitlab4j.api.models.Milestone;
-import org.gitlab4j.api.models.Note;
-import org.gitlab4j.api.models.NotificationSettings;
-import org.gitlab4j.api.models.OauthTokenResponse;
+import org.gitlab4j.api.models.*;
import org.gitlab4j.api.models.Package;
-import org.gitlab4j.api.models.PackageFile;
-import org.gitlab4j.api.models.PersonalAccessToken;
-import org.gitlab4j.api.models.Pipeline;
-import org.gitlab4j.api.models.PipelineSchedule;
-import org.gitlab4j.api.models.Project;
-import org.gitlab4j.api.models.ProjectAccessToken;
-import org.gitlab4j.api.models.ProjectApprovalsConfig;
-import org.gitlab4j.api.models.ProjectFetches;
-import org.gitlab4j.api.models.ProjectGroup;
-import org.gitlab4j.api.models.ProjectHook;
-import org.gitlab4j.api.models.ProjectUser;
-import org.gitlab4j.api.models.ProtectedBranch;
-import org.gitlab4j.api.models.ProtectedTag;
-import org.gitlab4j.api.models.PushRules;
-import org.gitlab4j.api.models.RegistryRepository;
-import org.gitlab4j.api.models.RelatedEpic;
-import org.gitlab4j.api.models.RelatedEpicLink;
-import org.gitlab4j.api.models.Release;
-import org.gitlab4j.api.models.RemoteMirror;
-import org.gitlab4j.api.models.RepositoryFile;
-import org.gitlab4j.api.models.Runner;
-import org.gitlab4j.api.models.RunnerDetail;
-import org.gitlab4j.api.models.SamlGroupLink;
-import org.gitlab4j.api.models.SearchBlob;
-import org.gitlab4j.api.models.Snippet;
-import org.gitlab4j.api.models.SshKey;
-import org.gitlab4j.api.models.SystemHook;
-import org.gitlab4j.api.models.Tag;
-import org.gitlab4j.api.models.Todo;
-import org.gitlab4j.api.models.Topic;
-import org.gitlab4j.api.models.TreeItem;
-import org.gitlab4j.api.models.Trigger;
-import org.gitlab4j.api.models.User;
-import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.services.JiraService;
import org.gitlab4j.api.services.SlackService;
import org.gitlab4j.api.webhook.ExternalStatusCheckEvent;
@@ -802,6 +704,12 @@ public void testUser() throws Exception {
assertTrue(compareJson(user, "user.json"));
}
+ @Test
+ public void testUploadedFile() throws Exception {
+ UploadedFile uploadedFile = unmarshalResource(UploadedFile.class, "uploaded-file.json");
+ assertTrue(compareJson(uploadedFile, "uploaded-file.json"));
+ }
+
@Test
public void testImpersonationToken() throws Exception {
ImpersonationToken token = unmarshalResource(ImpersonationToken.class, "impersonation-token.json");
diff --git a/src/test/resources/org/gitlab4j/api/uploaded-file.json b/src/test/resources/org/gitlab4j/api/uploaded-file.json
new file mode 100644
index 00000000..7ac48b4d
--- /dev/null
+++ b/src/test/resources/org/gitlab4j/api/uploaded-file.json
@@ -0,0 +1,11 @@
+{
+ "id": 1623,
+ "size": 435,
+ "filename": "some-feature.png",
+ "created_at": "2024-09-23T13:52:15Z",
+ "uploaded_by": {
+ "id": 54,
+ "username": "john.smith",
+ "name": "John Smith"
+ }
+}
\ No newline at end of file