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

[BUG]: CreateRepositoryRuleset Mutation Failing to Create Rules with Parameters #320

Open
1 task done
ProgrammingByPermutation opened this issue Jun 15, 2024 · 1 comment · May be fixed by #329
Open
1 task done
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@ProgrammingByPermutation

What happened?

The following code should create a new repository ruleset query that restricts branch updates on the default branch to PRs with passing status checks named ng test and ng lint.

var mut = new Mutation()
  .CreateRepositoryRuleset(new Arg<CreateRepositoryRulesetInput>(new CreateRepositoryRulesetInput {
    SourceId = id,
    Name = "main",
    Enforcement = RuleEnforcement.Active,
    Target = RepositoryRulesetTarget.Branch,
    Rules = new[] {
      new RepositoryRuleInput {
        Type = RepositoryRuleType.RequiredStatusChecks,
        Parameters = new RuleParametersInput {
          RequiredStatusChecks = new RequiredStatusChecksParametersInput {
            RequiredStatusChecks = new[] {
              new StatusCheckConfigurationInput {
                Context = "ng test"
              },
              new StatusCheckConfigurationInput {
                Context = "ng lint"
              }
            },
            StrictRequiredStatusChecksPolicy = true
          }
        }
      }
    },
    Conditions = new RepositoryRuleConditionsInput {
      RefName = new RefNameConditionTargetInput {
        Include = new[] { "~DEFAULT_BRANCH" },
        Exclude = new string[] { }
      }
    }
  })).Compile();

This code fails with an exception stating "Only one rule parameter type can be specified."

On closer inspection of the compiled query is comes out to the following:

mutation {
  createRepositoryRuleset(
    input: {
      clientMutationId: null
      sourceId: "..."
      name: "main"
      target: BRANCH
      rules: [
        {
          id: null
          type: REQUIRED_STATUS_CHECKS
          parameters: {
            update: null
            requiredDeployments: null
            pullRequest: null
            requiredStatusChecks: {
              requiredStatusChecks: [
                { context: "ng test", integrationId: null }
                { context: "ng lint", integrationId: null }
              ]
              strictRequiredStatusChecksPolicy: true
            }
            commitMessagePattern: null
            commitAuthorEmailPattern: null
            committerEmailPattern: null
            branchNamePattern: null
            tagNamePattern: null
            workflows: null
          }
        }
      ]
      conditions: {
        refName: { exclude: [], include: ["~DEFAULT_BRANCH"] }
        repositoryName: null
        repositoryId: null
        repositoryProperty: null
      }
      enforcement: ACTIVE
      bypassActors: null
    }
  )
}

If you pass this graphql to the GitHub GraphQL Explorer you get the same message.

The problem here is the parameters that are specified but nulled out in the following:

parameters: {
  update: null
  requiredDeployments: null
  pullRequest: null
  requiredStatusChecks: {
    requiredStatusChecks: [
      { context: "ng test", integrationId: null }
      { context: "ng lint", integrationId: null }
    ]
    strictRequiredStatusChecksPolicy: true
  }
  commitMessagePattern: null
  commitAuthorEmailPattern: null
  committerEmailPattern: null
  branchNamePattern: null
  tagNamePattern: null
  workflows: null
}

If you remove the nulls and make the query the following it works as expected:

mutation {
  createRepositoryRuleset(
    input: {
      clientMutationId: null
      sourceId: "..."
      name: "main"
      target: BRANCH
      rules: [
        {
          id: null
          type: REQUIRED_STATUS_CHECKS
          parameters: {
            requiredStatusChecks: {
              requiredStatusChecks: [
                { context: "ng test", integrationId: null }
                { context: "ng lint", integrationId: null }
              ]
              strictRequiredStatusChecksPolicy: true
            }
          }
        }
      ]
      conditions: {
        refName: { exclude: [], include: ["~DEFAULT_BRANCH"] }
        repositoryName: null
        repositoryId: null
        repositoryProperty: null
      }
      enforcement: ACTIVE
      bypassActors: null
    }
  ) {
    clientMutationId
  }
}

We need to update the compiler to not include the null fields for the parameters of this query.

Versions

Octokit.GraphQL 0.4.0-beta
net8.0

Relevant log output

Raw error as received from the GitHub GraphQL Explorer:
{
  "data": {
    "createRepositoryRuleset": null
  },
  "errors": [
    {
      "type": "UNPROCESSABLE",
      "path": [
        "createRepositoryRuleset"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "message": "Only one rule parameter type can be specified."
    }
  ]
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ProgrammingByPermutation ProgrammingByPermutation added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Jun 15, 2024
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Jun 17, 2024
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Jun 17, 2024
ProgrammingByPermutation added a commit to ProgrammingByPermutation/octokit.graphql.net that referenced this issue Nov 19, 2024
Adding the [SerializeIfNotNullAttribute] which can be applied to
properties serialized by the QuerySerializer to indicate they should
never be serialized when null.

As a proof of concept, the RuleParameterInput used in the creation of
rulesets for the repository was failing due to null properties being
seralized into the final output. This code now functions as expected.

I did not make a global change to no longer serialized all null values
as I anticipate that there are "side effects" we depend on where there
are expected null serialzations that will break if such a change is
made.

This is an "opt-in" feature that does not disturb the greater echosystem
that may depend on these "side effects".

octokit#320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

Successfully merging a pull request may close this issue.

2 participants