-
Notifications
You must be signed in to change notification settings - Fork 475
#1010 get .gitlab-ci.yml template #1026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.gitlab4j.api.models; | ||
|
||
import org.gitlab4j.api.utils.JacksonJson; | ||
|
||
public class CiYamlTemplate { | ||
|
||
private String name; | ||
private String content; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return (JacksonJson.toJsonString(this)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.gitlab4j.api.models; | ||
|
||
import java.util.List; | ||
import javax.ws.rs.core.GenericType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
import org.gitlab4j.api.AbstractApi; | ||
import org.gitlab4j.api.GitLabApi; | ||
import org.gitlab4j.api.GitLabApiException; | ||
|
||
/** | ||
* This class provides an entry point to all the GitLab CI YAML API calls. | ||
* | ||
* @see <a href="https://https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html">GitLab CI YAML API</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. link is wrong |
||
*/ | ||
public class CiYamlTemplatesApi extends AbstractApi { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the class should be named to match the title of the docs |
||
|
||
public CiYamlTemplatesApi(GitLabApi gitLabApi) { | ||
super(gitLabApi); | ||
} | ||
|
||
/** | ||
* Get all GitLab CI/CD YAML templates. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /templates/gitlab_ci_ymls</code></pre> | ||
* | ||
* @return a list of Gitlab CI YAML Templates | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public List<CiYamlTemplatesElement> getAllCiYamlTemplates() throws GitLabApiException { | ||
Response response = get(Response.Status.OK, null, "templates", "gitlab_ci_ymls"); | ||
return (response.readEntity(new GenericType<List<CiYamlTemplatesElement>>() {})); | ||
} | ||
|
||
/** | ||
* Get a single GitLab CI/CD YAML template. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /templates/gitlab_ci_ymls/:key</code></pre> | ||
* | ||
* @param key The key of the GitLab CI YAML template | ||
* @return an Gitlab CI YAML Template | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public CiYamlTemplate getSingleCiYamlTemplate(String key) throws GitLabApiException { | ||
Response response = get(Status.OK, null, "templates", "gitlab_ci_ymls", key); | ||
return (response.readEntity(CiYamlTemplate.class)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.gitlab4j.api.models; | ||
|
||
import org.gitlab4j.api.utils.JacksonJson; | ||
|
||
public class CiYamlTemplatesElement { | ||
|
||
private String key; | ||
private String name; | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return (JacksonJson.toJsonString(this)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.gitlab4j.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
import java.util.List; | ||
import org.gitlab4j.api.models.CiYamlTemplate; | ||
import org.gitlab4j.api.models.CiYamlTemplatesElement; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties | ||
* | ||
* TEST_PROJECT_NAME | ||
* TEST_HOST_URL | ||
* | ||
* If any of the above are NULL, all tests in this class will be skipped. | ||
*/ | ||
@Tag("integration") | ||
@ExtendWith(SetupIntegrationTestExtension.class) | ||
public class TestCiYamlTemplatesApi extends AbstractIntegrationTest { | ||
|
||
private static GitLabApi gitLabApi; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
gitLabApi = baseTestSetup(); | ||
} | ||
|
||
@BeforeEach | ||
public void beforeMethod() { | ||
assumeTrue(gitLabApi != null); | ||
} | ||
|
||
@Test | ||
public void testGetAllCiYamlTemplates() throws GitLabApiException { | ||
List<CiYamlTemplatesElement> ciYamlTemplatesElements = gitLabApi.getCiYamlTemplatesApi().getAllCiYamlTemplates(); | ||
assertAll( | ||
() -> assertNotNull(ciYamlTemplatesElements), | ||
() -> assertTrue(ciYamlTemplatesElements.size() > 0) | ||
); | ||
} | ||
|
||
@Test | ||
public void testGetSingleCiYamlTemplate() throws GitLabApiException { | ||
List<CiYamlTemplatesElement> ciYamlTemplatesElements = gitLabApi.getCiYamlTemplatesApi().getAllCiYamlTemplates(); | ||
assumeTrue(ciYamlTemplatesElements != null); | ||
assumeTrue(ciYamlTemplatesElements.size() > 0); | ||
String templateKey = ciYamlTemplatesElements.get(0).getKey(); | ||
CiYamlTemplate ciYamlTemplate = gitLabApi.getCiYamlTemplatesApi().getSingleCiYamlTemplate(templateKey); | ||
assertAll( | ||
() -> assertNotNull(ciYamlTemplate), | ||
() -> assertNotNull(ciYamlTemplate.getContent()), | ||
() -> assertEquals(templateKey, ciYamlTemplate.getName()) | ||
); | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Ruby", | ||
"content": "# This file is a template, and might need editing before it works on your project.\n# To contribute improvements to CI/CD templates, please follow the Development guide at:\n# https://docs.gitlab.com/ee/development/cicd/templates.html\n# This specific template is located at:\n# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Ruby.gitlab-ci.yml\n\n# Official language image. Look for the different tagged releases at:\n# https://hub.docker.com/r/library/ruby/tags/\nimage: ruby:latest\n\n# Pick zero or more services to be used on all builds.\n# Only needed when using a docker container to run your tests in.\n# Check out: https://docs.gitlab.com/ee/ci/services/index.html\nservices:\n - mysql:latest\n - redis:latest\n - postgres:latest\n\nvariables:\n POSTGRES_DB: database_name\n\n# Cache gems in between builds\ncache:\n paths:\n - vendor/ruby\n\n# This is a basic example for a gem or script which doesn't use\n# services such as redis or postgres\nbefore_script:\n - ruby -v # Print out ruby version for debugging\n # Uncomment next line if your rails app needs a JS runtime:\n # - apt-get update -q \u0026\u0026 apt-get install nodejs -yqq\n - bundle config set --local deployment true # Install dependencies into ./vendor/ruby\n - bundle install -j $(nproc)\n\n# Optional - Delete if not using `rubocop`\nrubocop:\n script:\n - rubocop\n\nrspec:\n script:\n - rspec spec\n\nrails:\n variables:\n DATABASE_URL: \"postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB\"\n script:\n - rails db:migrate\n - rails db:seed\n - rails test\n\n# This deploy job uses a simple deploy flow to Heroku, other providers, for example, AWS Elastic Beanstalk\n# are supported too: https://github.com/travis-ci/dpl\ndeploy:\n stage: deploy\n environment: production\n script:\n - gem install dpl\n - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_PRODUCTION_KEY\n" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
[ | ||
{ | ||
"key": "Android", | ||
"name": "Android" | ||
}, | ||
{ | ||
"key": "Android-Fastlane", | ||
"name": "Android-Fastlane" | ||
}, | ||
{ | ||
"key": "Auto-DevOps", | ||
"name": "Auto-DevOps" | ||
}, | ||
{ | ||
"key": "Bash", | ||
"name": "Bash" | ||
}, | ||
{ | ||
"key": "C++", | ||
"name": "C++" | ||
}, | ||
{ | ||
"key": "Chef", | ||
"name": "Chef" | ||
}, | ||
{ | ||
"key": "Clojure", | ||
"name": "Clojure" | ||
}, | ||
{ | ||
"key": "Code-Quality", | ||
"name": "Code-Quality" | ||
}, | ||
{ | ||
"key": "Crystal", | ||
"name": "Crystal" | ||
}, | ||
{ | ||
"key": "Deploy-ECS", | ||
"name": "Deploy-ECS" | ||
}, | ||
{ | ||
"key": "Django", | ||
"name": "Django" | ||
}, | ||
{ | ||
"key": "Docker", | ||
"name": "Docker" | ||
}, | ||
{ | ||
"key": "Elixir", | ||
"name": "Elixir" | ||
}, | ||
{ | ||
"key": "Go", | ||
"name": "Go" | ||
}, | ||
{ | ||
"key": "Gradle", | ||
"name": "Gradle" | ||
}, | ||
{ | ||
"key": "Grails", | ||
"name": "Grails" | ||
}, | ||
{ | ||
"key": "Julia", | ||
"name": "Julia" | ||
}, | ||
{ | ||
"key": "LaTeX", | ||
"name": "LaTeX" | ||
}, | ||
{ | ||
"key": "Laravel", | ||
"name": "Laravel" | ||
}, | ||
{ | ||
"key": "Managed-Cluster-Applications", | ||
"name": "Managed-Cluster-Applications" | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong package