Updated on 2024-07-05 GMT+08:00

Commit Association

With CodeArts Repo, you can associate each code commit with a work item of CodeArts Req.

  • Associated work items help developers accurately record tasks for fixing bugs and developing new features.
  • Associated work items allow project managers to view information such as change committer and committed content involved in each requirement and bug fixing task.

Commit: You can commit and save operations on files in the working directory, including creating, editing, and deleting files. The following shows the commit command, in which the -m parameter is mandatory and followed by the commit message.

git commit -m <commit_message>

On the CodeArts Repo console, a changed file can be saved only after you enter a commit message. Each saving operation on the console is a commit, and the mandatory message corresponds to the content after -m in the commit command.

CodeArts Repo automatically associates work items with code by capturing keywords from the commit message after -m. The most commonly used keyword is fix, which is the recommended keyword in the prompt. The keyword must meet the following format:

git commit -m "fix #<work_item_id> <commit_message>"

If a work item is successfully associated, the system automatically changes the work item status based on the configured code commit status transition. By default, the fix keyword sets the work item to the resolved state.

Example:

git commit -m "fix #123456 fixed this bug"

The work item 123456 is set to the resolved state after being pushed to CodeArts Repo.

CodeArts Repo allows you to associate work items with code on the local PC or on the console. The following describes the two methods.

  • Only members of the same project and repository can associate work items with code.
  • For the work item creator, specified modifier, or account (such as the project manager) that has the permission to modify all work items in the project, their association operations can change the work item status (new or resolved) and generate comment records. In the association records, Transition successful is displayed in the Result column. When you use an unauthorized account to perform operations, only association records are generated. The work item status is not changed, no comment record is generated, and Association successful is displayed in the Result column.

Associating a Work Item with Locally Committed Code

Prepare the Git environment on the local PC. For details, see Installing and Configuring Git. If you can access the repository (the corresponding remote repository has been associated), perform the following operations:

Create a file on the local master branch and push the file to the remote repository. During the push, use the fix keyword in -m to associate the work item task01 with code.

  • In this example, the master branch is modified to simplify the process so that you can quickly understand how to associate a work item with code committed on the local PC.
  • Do not modify the master branch in the actual situation. It is recommended that you create a branch for file operations, merge the changed file into the master branch, and push the master branch to the remote repository. (This is a default rule and good habit.)
  1. Right-click in the local repository folder to open the Git Bash client.
  2. Check whether the remote repository address is successfully associated.

    git remote -v          # View the remote repository address associated with the local repository.

    In the following figure, the underlined part indicates the remote repository address associated with the local repository, and the information before the address is the alias of the remote repository on the local PC.

    If the associated repository is not the one you want or no repository is associated, clone the desired repository to the local PC.

    After the clone is successful, run the git remote -v command again to verify the association.

  3. Check the repository status and switch to the master branch. (Skip this step for a repository cloned in the previous step.)

    git status             # Check the repository status. You can view the current branch and whether there are unsaved, uncommitted, and unpushed changes on the branch.
    git checkout master    # Switch to the master branch. Run the command when the current branch is not the master branch.

  4. Create a file in the local repository folder and name the file fileFor708206208.
  5. Add the new file to the temporary zone using Git Bash.

    git add fileFor708206208

  6. Commit the operation using Git Bash.

    git commit -m "fix #708206208 Task01"    #/ Use the fix keyword to associate task 01 whose ID is 708206208.

    708206208 is the ID of task01.

  7. Push the committed content to the associated CodeArts Repo repository using Git Bash.

    git push

    The command output varies depending on the repository structure. If 100% or done is displayed for all steps, the push is successful. Push failures are usually caused by invalid keys.

  8. Verify the association result.

    Go to the work item list and locate the work item whose ID is 708206208 to view its details.

    • The status is Resolved.
    • An associated code commit record is added. You can click the commit ID to view the details.
    • A comment is automatically generated to describe the work item association.

Associating Work Items with Code Committed on the Console

  1. Go to the repository details page.
  2. Create a file, enter a commit message starting with fix #708206209, and set other parameters as required. The following figure shows an example.

    708206209 is the ID of task02.

  3. Click OK. The system performs the following operations on the CodeArts Repo repository:

    Writes content to the new file.
    git add .
    git commit -m "fix #708206209 Task02"

    That is, the system commits the new file and associates it with the task02 work item using the fix keyword in the -m parameter.

  4. Verify the association.

    View the task02 work item.

    • The status is Resolved.
    • An associated code commit record is added. You can click the commit ID to view the details.
    • A comment is automatically generated to describe the work item association.