Step 3: Writing Code
CodeArts Repo provides Git-based online code management service, including code cloning/submission 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.
Using Branches
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 the stable running of Phoenix, a stable and continuously available master is required. The project manager suggests "function branches + request merges". 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.
Table 1 Creating a protected branch Configuration Item
Suggestion
Branch
Select master.
Push
Configure this parameter as required. In this example, the default configurations are used.
Merge
Configure this parameter as required. In this example, the default configurations are used.
Members
Select Push and Merge as required, and select a member from the drop-down list.
In this example, the default configurations are used.
If the protected branch master already exists on the page, click and modify the branch configuration as required.
- Create a function branch (this operation is performed by developer Chris in this document).
- Go to the Phoenix 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 and 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 Frontend display - Add store network menu as an example to describe how to modify and commit code.
- Choose
from the navigation pane, and click the Sprints tab.
In Sprint4, 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 information, #xxxxxx indicates the ID of the task for 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
from the navigation pane. 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 record
Reviewing Code and Merging Branches
- A 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 New.
- 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 reviewer and merger. Maggie reviews 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 the Approval Gate to complete the approval.
- Click Merge to merge the branch into master.
If you have selected Delete source branch after merge 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