Skip to content

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

@ProgrammingByPermutation

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    🔥 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions