Commit Action

Updated 1 month ago by Copado Solutions

Overview

The Commit action is a method of the Copado Multi-Cloud platform API that is used to perform the commit process.

The commit links changes to a user story, records them in a Git repository and then deploy them to the different environments in your pipeline. To do this, when you commit changes in a user story, Copado creates a feature branch with the changes and then merges that branch into the source environment branch.

As every action, the Commit action consists of three different parts:

This article will provide detailed information about the Commit action and the commit process for Multi-Cloud. The Commit action is a generic operation which is common to every platform. However, platform specific operations are managed in the Execution step.

Commit Process with the Commit Action

When you click on the Commit Changes button in the Commit page for Multi-Cloud, the following operations are performed:

  1. Invocable method
  2. Execution
  3. Callback
Invocable Method

Copado executes the invocable method, which is an Apex method that contains a set of standard operations used to prepare and validate all the necessary information for the subsequent execution.

This invocable method is called from standard functionality like the Commit Changes button in the User Story Commit page or CLI, but can also be invoked from other sources such as a webhook, Salesforce Flows, Apex code, etc.

This invocable method is responsible of performing, among others, the following operations:

  • Validate licenses and permissions.
  • Obtain a list of the files selected in the table or through CLI (including operation values and others).
  • Check if the Re-create Feature Branch option has to be applied.
  • Check if the Change Base Branch option has to be applied.
  • Create the user story metadata records.
  • Create the Git snapshot record.
  • Create the user story commit record.
Execution

When the invocable method completes the above-mentioned operations, it triggers the execution process, which consists of a job template that will contain the steps to execute the commit operation, which can vary depending on the platform, cloud or technology that you are working with.

This job template will be provided by the extension that you are using and it will be defined in the Commit Job Template field of the Pipeline. However, you can override this template by providing a different one in the Commit Job Template field of the Environment you’re operating in. If you define a job template in the Environment, it will be executed instead of the one specified in the Pipeline.

Then, the job template will perform the following actions:

  • Create or reuse the feature branch.
  • Retrieve the files changes from the source and commit them.
  • Push the feature branch changes to the version control.
The same process will apply either if you are committing your changes through the User Story Commit page or through CLI.

It is important to note that the configuration of the Re-create Feature Branch and Change Base Branch options in the User Story Commit page affects the creation of the feature branch and how the changes will be committed:

  • Re-create Feature Branch option:
    • If the feature branch does not exist, the job template will create a new one out of master/main by default, or out of a different one if it is specified. Then, the job template will commit the selected changes in that branch.
    • If the feature branch already exists and the Re-create Feature Branch checkbox is not selected in the User Story Commit page, Copado will commit the selected files in the existing feature branch.
    • If the feature branch already exists and the Re-create Feature Branch checkbox is selected in the User Story Commit page, Copado will delete the existing feature branch in the Git repository, create a new one out of master/main by default, or out of a different one if it is specified. Then, the job template will commit the selected changes in that branch.
  • Change Base Branch option:
    • If the Change Base Branch toggle is not enabled, the user story feature branch will be created out of master or main.
    • If the Change Base Branch toggle is enabled, the base branch will be the one specified in the Select Base Branch field.
    For further information about the Re-Create Feature Branch and Change Base Branch options, refer to the User Story Commit Page for Multi-Cloud article.

For further information about job templates, please refer to the Job Template Overview, How to Execute a Job Template and How to Build the Commit Page for the Commit Action in Multi-Cloud articles.

Callback

After the execution process is completed, Copado executes the callback, which is an Apex method that performs different types of operations, such as:

  • Update the Status field in the snapshot commit record.
  • Update the Latest Commit Date field in the user story record.
  • Notifies when the operation has finished.


How did we do?