Add support for Git 'put' params

This commit is contained in:
Kris De Volder
2017-01-21 11:46:07 -08:00
parent 3d8f38c238
commit f9a464cb8c
10 changed files with 121 additions and 22 deletions

View File

@@ -40,6 +40,9 @@ public class PipelineYmlSchema implements YamlSchema {
public final YTypeFactory f = new YTypeFactory();
public final YType t_string = f.yatomic("String");
public final YType t_ne_string = f.yatomic("String")
.parseWith(ValueParsers.NE_STRING);
public final YType t_strings = f.yseq(t_string);
public final YType t_pair = f.ybean("NameValuePair",
f.yprop("name", t_string),
@@ -64,9 +67,6 @@ public class PipelineYmlSchema implements YamlSchema {
// define schema types
TOPLEVEL_TYPE = f.ybean("Pipeline");
YAtomicType t_ne_string = f.yatomic("String");
t_ne_string.parseWith(ValueParsers.NE_STRING);
YAtomicType t_duration = f.yatomic("Duration");
t_duration.parseWith(ConcourseValueParsers.DURATION);
@@ -132,16 +132,19 @@ public class PipelineYmlSchema implements YamlSchema {
addProp(getStep, "resource", t_string);
addProp(getStep, "version", t_version);
addProp(getStep, "passed", f.yseq(jobName));
addProp(getStep, "params", f.contextAware("GetParams", (dc) ->
YType t_get_params = f.contextAware("GetParams", (dc) ->
resourceTypes.getInParamsType(getResourceType("get", models, dc))
));
);
addProp(getStep, "params", t_get_params);
addProp(getStep, "trigger", t_boolean);
YBeanType putStep = f.ybean("PutStep");
addProp(putStep, "put", resourceName);
addProp(putStep, "resource", jobName);
addProp(putStep, "params", t_params);
addProp(putStep, "get_params", t_params);
addProp(putStep, "params", f.contextAware("PutParams", (dc) ->
resourceTypes.getOutParamsType(getResourceType("put", models, dc))
));
addProp(putStep, "get_params", t_get_params);
YBeanType taskStep = f.ybean("TaskStep");
addProp(taskStep, "task", t_ne_string);
@@ -219,7 +222,8 @@ public class PipelineYmlSchema implements YamlSchema {
}
private void initializeDefaultResourceTypes() {
// git resource
////////////////////////////////////////////////////
// git
YBeanType gitSource = f.ybean("GitResourceSource");
addProp(gitSource, "uri", t_string).isRequired(true);
addProp(gitSource, "branch", t_string).isRequired(true);
@@ -242,8 +246,15 @@ public class PipelineYmlSchema implements YamlSchema {
addProp(gitGetParams, "disable_git_lfs", t_boolean);
YBeanType gitPutParams = f.ybean("GitPutParams");
resourceTypes.def("git", gitSource, gitGetParams, gitPutParams);
addProp(gitPutParams, "repository", t_ne_string).isRequired(true);
addProp(gitPutParams, "rebase", t_boolean);
addProp(gitPutParams, "tag", t_ne_string);
addProp(gitPutParams, "only_tag", t_boolean);
addProp(gitPutParams, "tag_prefix", t_string);
addProp(gitPutParams, "force", t_boolean);
addProp(gitPutParams, "annotate", t_ne_string);
resourceTypes.def("git", gitSource, gitGetParams, gitPutParams);
}
private String getResourceType(String resourceNameProp, ConcourseModel models, DynamicSchemaContext dc) {

View File

@@ -18,8 +18,7 @@ import org.springframework.ide.vscode.commons.yaml.schema.YType;
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType;
/**
* Keeps track of known resource types. For now this only keeps track of the resource-types that
* are built-in to concourse.
* Keeps track of known resource types.
*
* @author Kris De Volder
*/
@@ -81,4 +80,14 @@ public class ResourceTypeRegistry {
return null;
}
public YType getOutParamsType(String typeTag) {
if (typeTag!=null) {
ResourceTypeInfo v = resourceTypes.get(typeTag);
if (v!=null) {
return v.getOut();
}
}
return null;
}
}

View File

@@ -0,0 +1,5 @@
*Optional.* If specified the tag will be an
[annotated](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Annotated-Tags)
tag rather than a
[lightweight](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Lightweight-Tags)
tag. The value should be a path to a file containing the annotation message.

View File

@@ -0,0 +1,2 @@
*Optional.* When set to 'true' this will force the branch to be
pushed regardless of the upstream state.

View File

@@ -0,0 +1 @@
*Optional.* When set to 'true' push only the tags of a repo.

View File

@@ -0,0 +1,2 @@
*Optional.* If pushing fails with non-fast-forward, continuously
attempt rebasing and pushing.

View File

@@ -0,0 +1 @@
*Required.* The path of the repository to push to the source.

View File

@@ -0,0 +1,2 @@
*Optional.* If this is set then HEAD will be tagged. The value should be
a path to a file containing the name of the tag.

View File

@@ -0,0 +1,3 @@
*Optional.* If specified, the tag read from the file will be
prepended with this string. This is useful for adding `v` in front of
version numbers.

View File

@@ -853,7 +853,6 @@ public class PipelineYamlEditorTest {
);
}
@Ignore
@Test public void gitResourcePutParamsCompletions() throws Exception {
String context =
"resources:\n" +
@@ -869,19 +868,19 @@ public class PipelineYamlEditorTest {
assertContextualCompletions(context,
"<*>"
, // ===>
"repository: <*>"
,
"rebase: <*>"
,
"tag: <*>\n"
,
"only_tag: <*>"
,
"tag_prefix: <*>"
"annotate: <*>"
,
"force: <*>"
,
"annotate: <*>"
"only_tag: <*>"
,
"rebase: <*>"
,
"repository: <*>"
,
"tag: <*>"
,
"tag_prefix: <*>"
);
assertContextualCompletions(context,
"rebase: <*>"
@@ -903,6 +902,70 @@ public class PipelineYamlEditorTest {
);
}
@Test public void gitResourcePutParamsReconcile() throws Exception {
Editor editor;
editor = harness.newEditor(
"resources:\n" +
"- name: my-git\n" +
" type: git\n" +
"jobs:\n" +
"- name: do-stuff\n" +
" plan:\n" +
" - put: my-git\n" +
" params: {}\n"
);
editor.assertProblems("{}|'repository' is required");
editor = harness.newEditor(
"resources:\n" +
"- name: my-git\n" +
" type: git\n" +
"jobs:\n" +
"- name: do-stuff\n" +
" plan:\n" +
" - put: my-git\n" +
" params:\n" +
" repository: some-other-repo\n" +
" rebase: do-rebase\n" +
" only_tag: do-tag\n" +
" force: force-it\n"
);
editor.assertProblems(
"do-rebase|'boolean'",
"do-tag|'boolean'",
"force-it|'boolean'"
);
}
@Test public void gitResourcePutParamsHovers() throws Exception {
Editor editor = harness.newEditor(
"resources:\n" +
"- name: my-git\n" +
" type: git\n" +
"jobs:\n" +
"- name: do-stuff\n" +
" plan:\n" +
" - put: my-git\n" +
" params:\n" +
" repository: some-other-repo\n" +
" rebase: do-rebase\n" +
" tag: the-tag-file\n" +
" only_tag: do-tag\n" +
" tag_prefix: RELEASE\n" +
" force: force-it\n" +
" annotate: release-annotion\n"
);
editor.assertHoverContains("repository", "The path of the repository");
editor.assertHoverContains("rebase", "attempt rebasing");
editor.assertHoverContains("tag", "HEAD will be tagged");
editor.assertHoverContains("only_tag", "push only the tags");
editor.assertHoverContains("tag_prefix", "prepended with this string");
editor.assertHoverContains("force", "pushed regardless of the upstream state");
editor.assertHoverContains("annotate", "path to a file containing the annotation message");
}
@Test
public void contentAssistJobNames() throws Exception {
assertContextualCompletions(