Skip to content

Commit f1a7383

Browse files
committed
Initial commit (#171).
1 parent a273f67 commit f1a7383

File tree

5 files changed

+314
-0
lines changed

5 files changed

+314
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.gitlab4j.api.models;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlRootElement;
6+
7+
@XmlRootElement
8+
@XmlAccessorType(XmlAccessType.FIELD)
9+
public class FileUpload {
10+
11+
private String alt;
12+
private String url;
13+
private String markdown;
14+
15+
public String getAlt() {
16+
return alt;
17+
}
18+
19+
public void setAlt(String alt) {
20+
this.alt = alt;
21+
}
22+
23+
public String getUrl() {
24+
return url;
25+
}
26+
27+
public void setUrl(String url) {
28+
this.url = url;
29+
}
30+
31+
public String getMarkdown() {
32+
return markdown;
33+
}
34+
35+
public void setMarkdown(String markdown) {
36+
this.markdown = markdown;
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.util.Date;
4+
5+
import javax.xml.bind.annotation.XmlAccessType;
6+
import javax.xml.bind.annotation.XmlAccessorType;
7+
import javax.xml.bind.annotation.XmlRootElement;
8+
9+
@XmlRootElement
10+
@XmlAccessorType(XmlAccessType.FIELD)
11+
public class PushRule {
12+
13+
private Integer id;
14+
private Integer projectId;
15+
private String commitMessageRegex;
16+
private String branchNameRegex;
17+
private Boolean denyDeleteTag;
18+
private Date createdAt;
19+
private Boolean memberCheck;
20+
private Boolean preventSecrets;
21+
private String authorEmailRegex;
22+
private String fileNameRegex;
23+
private Integer maxFileSize;
24+
25+
public Integer getId() {
26+
return id;
27+
}
28+
29+
public void setId(Integer id) {
30+
this.id = id;
31+
}
32+
33+
public Integer getProjectId() {
34+
return projectId;
35+
}
36+
37+
public void setProjectId(Integer projectId) {
38+
this.projectId = projectId;
39+
}
40+
41+
public PushRule withProjectId(Integer projectId) {
42+
this.projectId = projectId;
43+
return (this);
44+
}
45+
46+
public String getCommitMessageRegex() {
47+
return commitMessageRegex;
48+
}
49+
50+
public void setCommitMessageRegex(String commitMessageRegex) {
51+
this.commitMessageRegex = commitMessageRegex;
52+
}
53+
54+
public PushRule withCommitMessageRegex(String commitMessageRegex) {
55+
this.commitMessageRegex = commitMessageRegex;
56+
return (this);
57+
}
58+
59+
public String getBranchNameRegex() {
60+
return branchNameRegex;
61+
}
62+
63+
public void setBranchNameRegex(String branchNameRegex) {
64+
this.branchNameRegex = branchNameRegex;
65+
}
66+
67+
public PushRule withBranchNameRegex(String branchNameRegex) {
68+
this.branchNameRegex = branchNameRegex;
69+
return (this);
70+
}
71+
72+
public Boolean getDenyDeleteTag() {
73+
return denyDeleteTag;
74+
}
75+
76+
public void setDenyDeleteTag(Boolean denyDeleteTag) {
77+
this.denyDeleteTag = denyDeleteTag;
78+
}
79+
80+
public PushRule withDenyDeleteTag(Boolean denyDeleteTag) {
81+
this.denyDeleteTag = denyDeleteTag;
82+
return (this);
83+
}
84+
85+
public Date getCreatedAt() {
86+
return createdAt;
87+
}
88+
89+
public void setCreatedAt(Date createdAt) {
90+
this.createdAt = createdAt;
91+
}
92+
93+
public Boolean getMemberCheck() {
94+
return memberCheck;
95+
}
96+
97+
public void setMemberCheck(Boolean memberCheck) {
98+
this.memberCheck = memberCheck;
99+
}
100+
101+
public PushRule withMemberCheck(Boolean memberCheck) {
102+
this.memberCheck = memberCheck;
103+
return (this);
104+
}
105+
106+
public Boolean getPreventSecrets() {
107+
return preventSecrets;
108+
}
109+
110+
public void setPreventSecrets(Boolean preventSecrets) {
111+
this.preventSecrets = preventSecrets;
112+
}
113+
114+
public PushRule withPreventSecrets(Boolean preventSecrets) {
115+
this.preventSecrets = preventSecrets;
116+
return (this);
117+
}
118+
119+
public String getAuthorEmailRegex() {
120+
return authorEmailRegex;
121+
}
122+
123+
public void setAuthorEmailRegex(String authorEmailRegex) {
124+
this.authorEmailRegex = authorEmailRegex;
125+
}
126+
127+
public PushRule withAuthorEmailRegex(String authorEmailRegex) {
128+
this.authorEmailRegex = authorEmailRegex;
129+
return (this);
130+
}
131+
132+
public String getFileNameRegex() {
133+
return fileNameRegex;
134+
}
135+
136+
public void setFileNameRegex(String fileNameRegex) {
137+
this.fileNameRegex = fileNameRegex;
138+
}
139+
140+
public PushRule withFileNameRegex(String fileNameRegex) {
141+
this.fileNameRegex = fileNameRegex;
142+
return (this);
143+
}
144+
145+
public Integer getMaxFileSize() {
146+
return maxFileSize;
147+
}
148+
149+
public void setMaxFileSize(Integer maxFileSize) {
150+
this.maxFileSize = maxFileSize;
151+
}
152+
153+
public PushRule withMaxFileSize(Integer maxFileSize) {
154+
this.maxFileSize = maxFileSize;
155+
return (this);
156+
}
157+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package org.gitlab4j.api;
2+
3+
import static org.junit.Assert.assertNotNull;
4+
import static org.junit.Assume.assumeTrue;
5+
6+
import java.io.File;
7+
8+
import org.gitlab4j.api.GitLabApi.ApiVersion;
9+
import org.gitlab4j.api.models.FileUpload;
10+
import org.gitlab4j.api.models.Project;
11+
import org.junit.Before;
12+
import org.junit.BeforeClass;
13+
import org.junit.FixMethodOrder;
14+
import org.junit.Test;
15+
import org.junit.runners.MethodSorters;
16+
17+
/**
18+
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
19+
*
20+
* TEST_NAMESPACE
21+
* TEST_PROJECT_NAME
22+
* TEST_HOST_URL
23+
* TEST_PRIVATE_TOKEN
24+
*
25+
* If any of the above are NULL, all tests in this class will be skipped.
26+
*/
27+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
28+
public class TestFileUpload {
29+
30+
// The following needs to be set to your test repository
31+
private static final String TEST_PROJECT_NAME;
32+
private static final String TEST_NAMESPACE;
33+
private static final String TEST_HOST_URL;
34+
private static final String TEST_PRIVATE_TOKEN;
35+
static {
36+
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
37+
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
38+
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
39+
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
40+
}
41+
42+
private static GitLabApi gitLabApi;
43+
44+
public TestFileUpload() {
45+
super();
46+
}
47+
48+
@BeforeClass
49+
public static void setup() {
50+
51+
String problems = "";
52+
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
53+
problems += "TEST_NAMESPACE cannot be empty\n";
54+
}
55+
56+
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
57+
problems += "TEST_PROJECT_NAME cannot be empty\n";
58+
}
59+
60+
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
61+
problems += "TEST_HOST_URL cannot be empty\n";
62+
}
63+
64+
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
65+
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
66+
}
67+
68+
if (problems.isEmpty()) {
69+
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
70+
} else {
71+
System.err.print(problems);
72+
}
73+
}
74+
75+
@Before
76+
public void beforeMethod() {
77+
assumeTrue(gitLabApi != null);
78+
}
79+
80+
@Test
81+
public void testFileUpload() throws GitLabApiException {
82+
83+
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
84+
assertNotNull(project);
85+
86+
File fileToUpload = new File("README.md");
87+
FileUpload fileUpload = gitLabApi.getProjectApi().uploadFile(project.getId(), fileToUpload, null);
88+
assertNotNull(fileUpload);
89+
}
90+
91+
@Test
92+
public void testFileUploadWithMediaType() throws GitLabApiException {
93+
94+
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
95+
assertNotNull(project);
96+
97+
File fileToUpload = new File("README.md");
98+
FileUpload fileUpload = gitLabApi.getProjectApi().uploadFile(project.getId(), fileToUpload, "text/markdown");
99+
assertNotNull(fileUpload);
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"alt": "dk",
3+
"url": "/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png",
4+
"markdown": "![dk](/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png)"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": 1,
3+
"project_id": 3,
4+
"commit_message_regex": "Fixes \\d +\\",
5+
"branch_name_regex": "",
6+
"deny_delete_tag": false,
7+
"created_at": "2012-10-12T17:04:47Z",
8+
"member_check": false,
9+
"prevent_secrets": false,
10+
"author_email_regex": "",
11+
"file_name_regex": "",
12+
"max_file_size": 5
13+
}

0 commit comments

Comments
 (0)