Skip to content

Extend GraphQL API to commit to a new branch in a single operation

Miguel Rincon requested to merge 263144-commit-to-new-branch into master

What does this MR do?

Extend resolver to commit to a new branch

Users may want to create a new branch along with their commit, as when creating a new merge request.

This merge request adds a new optional parameter "startBranch" to the commitCreate mutation, so users can also add a new branch when creating a commit

Example mutation

This mutation creates a new branch with the new commit:

mutation commitCIFileMutation(
  $projectPath: ID!
  $branch: String!
  $startBranch: String!
  $message: String!
  $filePath: String!
  $lastCommitId: String!
  $content: String
) {
  commitCreate(
    input: {
      projectPath: $projectPath
      branch: $branch,
      startBranch: $startBranch,
      message: $message
      actions: [
        { action: UPDATE, filePath: $filePath, lastCommitId: $lastCommitId, content: $content }
      ]
    }
  ) {
    commit {
      id
    }
    errors
  }
}
{
  "branch": "new-branch",
  "startBranch": "master",
  "content": "stages:\n  - test\n\nvariables:\n  TEST: \n    value: \"HELLO 2\"\n    description: \"This variable makes cakes delicious\"\n  TEST_2:\n    value: \"HELLO TOO\"\n    description: \"\"\n  TEST_3: \"HELLO 3\"\n\ntest_variable:\n  stage: test\n  script:\n    - echo \"$TEST\"",
  "filePath": ".gitlab-ci.yml",
  "lastCommitId": "e270ea9cb5c597281f32160e3c769b1b7f9a019b",
  "message": "Update .gitlab-ci.yml file",
  "projectPath": "root/my-ci-variables"
}

Screenshots (strongly suggested)

GraphiQL

Screen_Shot_2020-11-11_at_11.59.26_AM

Example use case

When commiting changes to a file, we may want to choose a new branch to commit to, and even open a new merge request.

2020-11-09_15.42.07

See more at the next MR: !47083 (merged).

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #263144 (closed)

Edited by Miguel Rincon

Merge request reports

Loading