Step 3: Writing Code
CodeArts Repo provides Git-based online code management service, including code cloning/commit and branch management.
This section uses store network query as an example to describe how to manage and develop source code. Store network query is a high-priority story.
In this sample project, code is developed in a branch. Developer Chris creates a branch in a code repository, develops code, and submits a merge request. Project manager Maggie approves the request and then merges it to the master branch.
Managing Code with a Branch
A branch is a tool for parallel feature development. Branches enable you to diverge from the main line of development and continue to do work without messing with that main line.
When a code repository is created, there is a default branch named master, that is, the main line. To ensure stable running of the Phoenix Mall, a stable and continuously available master is required. The project manager suggests "function branches + merge requests". Each function branch must be reviewed by other members in the team before merge.
- Set master as a protected branch (this operation is performed by project manager Maggie in this document).
- Go to the Phoenix Mall project, choose from the navigation pane, and locate the code repository phoenix-sample.
- Go to the code repository by clicking its name and click the Settings tab. Choose from the navigation pane.
- Click Create Protected Branch. Complete the settings by referring to the following table and click OK.
If the protected branch master already exists on the page, click and modify the branch configuration as required.
Table 1 Creating a protected branch Configuration Item
Suggestion
Branch
Select master.
Push
Retain the default value.
Merge
Retain the default value.
Members
Retain the default value.
- Create a function branch (this operation is performed by developer Chris in this document).
- Go to the Phoenix Mall project. Choose Code > Repo. Find the phoenix-sample in the repository.
- Click the repository name to access the code repository. On the Code tab, click Branches.
- Click Create Branch, set the branch information by referring to Table 2, and click OK.
Modifying and Committing Code
The store network query function is divided into frontend display and backend management tasks during sprint planning. This section uses task Frontend display - Add store network menu as an example to describe how to modify and commit code.
- Choose Work from the navigation pane, and click the Sprints tab.
In sprint 4, find the task Frontend display - Add store network menu, and change the task status to Developing.
- Choose phoenix-sample repository. , and find the
- Go to the code repository by clicking its name and click the Code tab.
- Click master above the file list and select the branch Feature-Store from the drop-down list.
- Find vote/templates/store-network.html in the file list and open it.
- Click , add the store address specified in the story, enter the commit message Store list added in the text box at the bottom of the page, and click OK.
<ul> <li>Branch A: 123 meters to the departure floor, Terminal 1, Airport E</li> <li>Branch B: No. 456, Street G, Area F</li> <li>Branch C: No. 789, Street J, Area H</li> <li>Branch D: West side of Building K, Avenue L, Area K</li> </ul>
- Open and edit the /vote/templates/index.html file in the same way.
Add the menu Store Network in line 179, enter the commit message fix #xxxxxx Frontend display - Add store network menu, and click OK.
In the preceding message, #xxxxxx indicates the ID of task Frontend display - Add store network menu, which is obtained from the work item list.<li class="nav-item"> <a href="store-network" class="nav-link">Store network</a> </li>
- Choose Work from the navigation pane, and click the Sprints tab.
In sprint 4, find the task Frontend display - Add store network menu.
- Click the task name. The task status automatically changes to Resolved on the details page.
- Click the Associated tab. Under Code Commit Records, a record is displayed with the commit message configured in the previous step.
Figure 1 Code commit records
Reviewing Code and Merging Branches
- The developer initiates a merge request.
After coding, developer Chris initiates a merge request to merge their function branch into the master.
- Go to the code repository, click the Merge Requests tab, and click Create Merge Request.
- Set the source branch to Feature-Store and the target branch to master, and click Next.
- Edit the merge request details by referring to Table 3.
- Click Create Merge Request to complete the creation.
- The project manager reviews the code and merges the commit request.
In this document, project manager Maggie is both the approver and merger. Maggie approves the request content and merges the request.
- Go to the code repository, click the Merge Requests tab, and find the merge request created by developer Chris.
- Click the request to view details.
- Leave comments on the page. Click Approve in Approval Gate to complete the approval.
- Click Merge to merge the branch into master.
If you have selected Delete source branch after merged when creating a merge request, the branch Feature-Store will be deleted after the branch merge is complete.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot