Commit f1a73832 authored by Greg Messner's avatar Greg Messner
Browse files

Initial commit (#171).

parent a273f674
package org.gitlab4j.api.models;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class FileUpload {
private String alt;
private String url;
private String markdown;
public String getAlt() {
return alt;
}
public void setAlt(String alt) {
this.alt = alt;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMarkdown() {
return markdown;
}
public void setMarkdown(String markdown) {
this.markdown = markdown;
}
}
package org.gitlab4j.api.models;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class PushRule {
private Integer id;
private Integer projectId;
private String commitMessageRegex;
private String branchNameRegex;
private Boolean denyDeleteTag;
private Date createdAt;
private Boolean memberCheck;
private Boolean preventSecrets;
private String authorEmailRegex;
private String fileNameRegex;
private Integer maxFileSize;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProjectId() {
return projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public PushRule withProjectId(Integer projectId) {
this.projectId = projectId;
return (this);
}
public String getCommitMessageRegex() {
return commitMessageRegex;
}
public void setCommitMessageRegex(String commitMessageRegex) {
this.commitMessageRegex = commitMessageRegex;
}
public PushRule withCommitMessageRegex(String commitMessageRegex) {
this.commitMessageRegex = commitMessageRegex;
return (this);
}
public String getBranchNameRegex() {
return branchNameRegex;
}
public void setBranchNameRegex(String branchNameRegex) {
this.branchNameRegex = branchNameRegex;
}
public PushRule withBranchNameRegex(String branchNameRegex) {
this.branchNameRegex = branchNameRegex;
return (this);
}
public Boolean getDenyDeleteTag() {
return denyDeleteTag;
}
public void setDenyDeleteTag(Boolean denyDeleteTag) {
this.denyDeleteTag = denyDeleteTag;
}
public PushRule withDenyDeleteTag(Boolean denyDeleteTag) {
this.denyDeleteTag = denyDeleteTag;
return (this);
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Boolean getMemberCheck() {
return memberCheck;
}
public void setMemberCheck(Boolean memberCheck) {
this.memberCheck = memberCheck;
}
public PushRule withMemberCheck(Boolean memberCheck) {
this.memberCheck = memberCheck;
return (this);
}
public Boolean getPreventSecrets() {
return preventSecrets;
}
public void setPreventSecrets(Boolean preventSecrets) {
this.preventSecrets = preventSecrets;
}
public PushRule withPreventSecrets(Boolean preventSecrets) {
this.preventSecrets = preventSecrets;
return (this);
}
public String getAuthorEmailRegex() {
return authorEmailRegex;
}
public void setAuthorEmailRegex(String authorEmailRegex) {
this.authorEmailRegex = authorEmailRegex;
}
public PushRule withAuthorEmailRegex(String authorEmailRegex) {
this.authorEmailRegex = authorEmailRegex;
return (this);
}
public String getFileNameRegex() {
return fileNameRegex;
}
public void setFileNameRegex(String fileNameRegex) {
this.fileNameRegex = fileNameRegex;
}
public PushRule withFileNameRegex(String fileNameRegex) {
this.fileNameRegex = fileNameRegex;
return (this);
}
public Integer getMaxFileSize() {
return maxFileSize;
}
public void setMaxFileSize(Integer maxFileSize) {
this.maxFileSize = maxFileSize;
}
public PushRule withMaxFileSize(Integer maxFileSize) {
this.maxFileSize = maxFileSize;
return (this);
}
}
package org.gitlab4j.api;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import java.io.File;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Project;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
*
* TEST_NAMESPACE
* TEST_PROJECT_NAME
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestFileUpload {
// The following needs to be set to your test repository
private static final String TEST_PROJECT_NAME;
private static final String TEST_NAMESPACE;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
private static GitLabApi gitLabApi;
public TestFileUpload() {
super();
}
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
}
@Test
public void testFileUpload() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(project);
File fileToUpload = new File("README.md");
FileUpload fileUpload = gitLabApi.getProjectApi().uploadFile(project.getId(), fileToUpload, null);
assertNotNull(fileUpload);
}
@Test
public void testFileUploadWithMediaType() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(project);
File fileToUpload = new File("README.md");
FileUpload fileUpload = gitLabApi.getProjectApi().uploadFile(project.getId(), fileToUpload, "text/markdown");
assertNotNull(fileUpload);
}
}
{
"alt": "dk",
"url": "/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png",
"markdown": "![dk](/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png)"
}
\ No newline at end of file
{
"id": 1,
"project_id": 3,
"commit_message_regex": "Fixes \\d +\\",
"branch_name_regex": "",
"deny_delete_tag": false,
"created_at": "2012-10-12T17:04:47Z",
"member_check": false,
"prevent_secrets": false,
"author_email_regex": "",
"file_name_regex": "",
"max_file_size": 5
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment