Skip to content
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

Added missing attributes for ProjectApi #1237

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

yarisvt
Copy link

@yarisvt yarisvt commented Mar 28, 2025

Added missing attributes to the ProjectApi

@@ -789,7 +828,7 @@ public void setBuildCoverageRegex(String buildCoverageRegex) {

public Project withBuildCoverageRegex(String buildCoverageRegex) {
this.buildCoverageRegex = buildCoverageRegex;
return this;
return (this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we need those brackets.

I would just do this:

Suggested change
return (this);
return this;

Copy link
Collaborator

@jmini jmini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a very good addition.

The example file project.json used in unit-test should be updated to match the changes made to the model class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the file project.json?
https://github.com/gitlab4j/gitlab4j-api/blob/fe14e34f0ab11e9f06f52765f86fbc0d72caa3dd/gitlab4j-models/src/test/resources/org/gitlab4j/models/project.json
Ideally with values coming from an existing from a real REST call.

This way we would we would ensure that your changes are correctly serialized and deserialized.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some properties are only configurable with a Premium/Ultimate gitlab server, which I unfortenately do not have access to, so I've used an accepted value based on the documentation:

option type value I used
use_custom_template boolean false
external_authorization_classification_label string "label"
mirror_trigger_builds boolean false
only_allow_merge_if_all_status_checks_passed boolean false
group_with_project_templates_id integer 1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some properties are only configurable with a Premium/Ultimate gitlab server, which I unfortenately do not have access to

Yes this is a pity… even for working on gitlab4j there is no good way to access such a license (or I didn't asked at the correct place)

Comment on lines 139 to 141
"avatar" : null,
"group_with_project_templates_id" : null,
"public_builds" : null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using null in those test file does not work with the unit test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I missed those. I have also removed the avatar property, since that can only be used with a multipart/form-data and I now saw that there already is a setProjectAvatar method that uses this property

public class ContainerExpirationPolicy implements Serializable {
private static final long serialVersionUID = 1L;

private String cadence;
private Boolean enabled;

@JsonProperty("keep_n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the way the models are written, we are not using @JsonProperty. There was an attempt in #1198, but it never was finished.

For consistency reason, I would not add this now.

Copy link
Author

@yarisvt yarisvt Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to use @JsonProperty, so that the snake_case variant is used, instead of the camelCase.

With @JsonProperty:

{
  "cadence" : "1month",
  "enabled" : true,
  "keep_n" : 100,
  "older_than" : "7d",
  "name_regex" : ".*-development",
  "name_regex_keep" : ".*-main"
}

Without @JsonProperty:

{
    "cadence" : "1month",
    "enabled" : true,
    "keepN" : 100,
    "olderThan" : "7d",
    "nameRegex" : ".*-development",
    "nameRegexKeep" : ".*-main"
  }

Additionally, I also saw it used in Project itself:

    @JsonProperty("_links")
    private Map<String, String> links;

* @throws GitLabApiException if any exception occurs
*/
public Project setProjectContainerExpirationPolicy(
Object projectIdOrPath, ContainerExpirationPolicyAttributes containerExpirationPolicyAttributes)
Copy link
Collaborator

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 be null)

Copy link
Author

@yarisvt yarisvt Apr 4, 2025

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, while container_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 the container_expiration_policy_attributes is serialized as JSON:

{
  "cadence" : "1month",
  "enabled" : true,
  "keep_n" : 100,
  "older_than" : "7d",
  "name_regex" : ".*-development",
  "name_regex_keep" : ".*-main"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants