-
Notifications
You must be signed in to change notification settings - Fork 467
Added missing attributes for ProjectApi #1237
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 5 commits
c26c845
623f9ab
23bad2d
1220a9c
ce735e4
e73c2b2
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,119 @@ | ||
package org.gitlab4j.api.models; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.gitlab4j.models.utils.JacksonJson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class ContainerExpirationPolicy implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private String cadence; | ||
private Boolean enabled; | ||
|
||
@JsonProperty("keep_n") | ||
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. Currently the way the models are written, we are not using For consistency reason, I would not add this now. 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 had to use With {
"cadence" : "1month",
"enabled" : true,
"keep_n" : 100,
"older_than" : "7d",
"name_regex" : ".*-development",
"name_regex_keep" : ".*-main"
} Without {
"cadence" : "1month",
"enabled" : true,
"keepN" : 100,
"olderThan" : "7d",
"nameRegex" : ".*-development",
"nameRegexKeep" : ".*-main"
} Additionally, I also saw it used in @JsonProperty("_links")
private Map<String, String> links; |
||
private Integer keepN; | ||
|
||
@JsonProperty("older_than") | ||
private String olderThan; | ||
|
||
@JsonProperty("name_regex") | ||
private String nameRegex; | ||
|
||
@JsonProperty("name_regex_keep") | ||
private String nameRegexKeep; | ||
|
||
private String nextRunAt; | ||
|
||
public String getCadence() { | ||
return cadence; | ||
} | ||
|
||
public void setCadence(String cadence) { | ||
this.cadence = cadence; | ||
} | ||
|
||
public ContainerExpirationPolicy withCadence(String cadence) { | ||
this.cadence = cadence; | ||
return this; | ||
} | ||
|
||
public Boolean getEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(Boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public ContainerExpirationPolicy withEnabled(Boolean enabled) { | ||
this.enabled = enabled; | ||
return this; | ||
} | ||
|
||
public Integer getKeepN() { | ||
return keepN; | ||
} | ||
|
||
public void setKeepN(Integer keepN) { | ||
this.keepN = keepN; | ||
} | ||
|
||
public ContainerExpirationPolicy withKeepN(Integer keepN) { | ||
this.keepN = keepN; | ||
return this; | ||
} | ||
|
||
public String getOlderThan() { | ||
return olderThan; | ||
} | ||
|
||
public void setOlderThan(String olderThan) { | ||
this.olderThan = olderThan; | ||
} | ||
|
||
public ContainerExpirationPolicy withOlderThan(String olderThan) { | ||
this.olderThan = olderThan; | ||
return this; | ||
} | ||
|
||
public String getNameRegex() { | ||
return nameRegex; | ||
} | ||
|
||
public void setNameRegex(String nameRegex) { | ||
this.nameRegex = nameRegex; | ||
} | ||
|
||
public ContainerExpirationPolicy withNameRegex(String nameRegex) { | ||
this.nameRegex = nameRegex; | ||
return this; | ||
} | ||
|
||
public String getNameRegexKeep() { | ||
return nameRegexKeep; | ||
} | ||
|
||
public void setNameRegexKeep(String nameRegexKeep) { | ||
this.nameRegexKeep = nameRegexKeep; | ||
} | ||
|
||
public ContainerExpirationPolicy withNameRegexKeep(String nameRegexKeep) { | ||
this.nameRegexKeep = nameRegexKeep; | ||
return this; | ||
} | ||
|
||
public String getNextRunAt() { | ||
return nextRunAt; | ||
} | ||
|
||
public void setNextRunAt(String nextRunAt) { | ||
this.nextRunAt = nextRunAt; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return (JacksonJson.toJsonString(this)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.gitlab4j.api.models; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.gitlab4j.models.utils.JacksonJson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class ContainerExpirationPolicyAttributes implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@JsonProperty("container_expiration_policy_attributes") | ||
private ContainerExpirationPolicy containerExpirationPolicyAttributes; | ||
|
||
public ContainerExpirationPolicy getContainerExpirationPolicyAttributes() { | ||
return containerExpirationPolicyAttributes; | ||
} | ||
|
||
public void setContainerExpirationPolicyAttributes(ContainerExpirationPolicy containerExpirationPolicyAttributes) { | ||
this.containerExpirationPolicyAttributes = containerExpirationPolicyAttributes; | ||
} | ||
|
||
public ContainerExpirationPolicyAttributes withContainerExpirationPolicyAttributes( | ||
ContainerExpirationPolicy containerExpirationPolicyAttributes) { | ||
this.containerExpirationPolicyAttributes = containerExpirationPolicyAttributes; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return (JacksonJson.toJsonString(this)); | ||
} | ||
} |
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.
Why aren't you using just
ContainerExpirationPolicy
as parameter?Inside the method, you could create a new Project and pass the parameter to it with
withContainerExpirationPolicy(..)
If you serialise that project instance you will get the same result as with
containerExpirationPolicyAttributes.toString()
(since all the other fields will benull
)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.
I tried that before, but it does not work, I keep getting this error:
container_expiration_policy_attributes is invalid
According to the documentation,
container_expiration_policy_attributes
is used in the create/edit API to modify the policy, whilecontainer_expiration_policy
is used in the list API to list the policy.Also, there is an example which updates the policy, which uses
--header 'Content-Type: application/json;charset=UTF-8'
I think it doesn't work with
withContainerExpirationPolicy(..)
. since that request eventually uses--header 'Content-Type: application/x-www-form-urlencoded'
. But thecontainer_expiration_policy_attributes
is serialized as JSON: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.
The gitlab REST API is very flexible and accept the request to be either a JSON body, a regular HTTP Form Data, query parameters, …
I understand why you need a different method
setProjectContainerExpirationPolicy(..)
because here you are sending a project update request where theProject
is serialised as Body.My point was that
ContainerExpirationPolicyAttributes
model is not really necessary.You could do something like (not tested):
I don't understand why this would not work.
For me
request.toString()
withrequest
being aProject
instance is the same as yourcontainerExpirationPolicyAttributes.toString()
where yourcontainerExpirationPolicyAttributes
instance is of typeContainerExpirationPolicyAttributes
.And it removes the need for a
ContainerExpirationPolicyAttributes
.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.
Right, I now see that there is also
withParam(String name, Map<String, ?> variables, boolean required)
method inGitLabApiForm
which correctly sets form fields for a Map. I can just use that withcontainer_expiration_policy_attributes
, that also works.