☁️End-to-End CodeArts Project Management Part 1: Leveraging APIs and SSH for Req, Repo, and Check

Ertugrul Basar
Huawei Developers
Published in
10 min readAug 8, 2023
CodeArts

Warning: The API endpoints and URIs may change in the future. Make sure they are not deprecated. You can refer to support links

Part 2 is now live!

🔦Introduction

Hi everyone🙌, in this article, I will show you how to develop a project on CodeArts Req, Repo, and Check using API and SSH, without relying on the UI. This work serves as a guideline and provides important information on API usage in CodeArts, which you may find useful for larger projects in the future. After this article, I will write Part 2, which will cover CodeArts Build and Deploy services. If you are ready, let’s get started ⚡️

💻Demo

Before we begin the demo, I’d like to provide you with a brief overview of what we’ll cover. We’ll start with CodeArts Req, where we’ll manage the project. Next, we’ll create a repository on CodeArts Repo and upload our code using SSH. Finally, we’ll perform a static code check on the code we uploaded using CodeArts Check. While we’ll primarily use the API for these steps and we are going to use both Postman and Huawei Cloud API Explorer, I’ll occasionally show you the CodeArts UI on a web browser to help you understand the successful operations we perform throughout the process. Let’s proceed with the demo.

Prerequisites for this demo:

1️⃣Project on CodeArts and its project_id (or project_uuid)

As you may have guessed, the first step is to create a project on the CodeArts page. I’ll guide you through the process step by step, and once the project is created, we’ll need to note down the project_id. We’ll use this project_id in the API requests we’ll send later on. Let’s begin the project creation process.

After reaching the CodeArts Dashboard, you can click on “Access Service”, located on the top right side of the page.

CodeArts Dashboard

Next, click on “Create Page”, which is also located on the top right side of the page.

CodeArts Homepage

Here, we will select “Scrum” as the project type.

CodeArts Create Project — 1

After giving our project a name, we will click “OK”, and the project will be created.

CodeArts Create Project — 2

Once the project is created, make sure to note down the project_id, which is the string I indicated in the screenshot below. This project_id will be used for API requests in the subsequent steps.

CodeArts Project1

2️⃣CodeArts Service Endpoints

When you create an API request, you need an endpoint and URI. I will give you the URIs step by step, but here I will give you the endpoints for LA-Mexico City2 Region:

3️⃣X-Auth-Token

In Huawei Cloud, API requests are authenticated using token-based authentication. This token grants temporary permissions, and you need to include it in the header section of your requests to obtain the necessary permissions. If you want to learn how to use APIs with Huawei Cloud using Postman and obtain a token, you can refer to this article for detailed instructions.

4️⃣SSH Key

When you push or pull code from the CodeArts Repo repository, the repository needs to verify your identity and permissions. To establish a secure connection between your local computer and CodeArts Repo under your account, an SSH key is used. Before connecting to Repo using SSH, you need to generate an SSH key on your computer and configure it on CodeArts Repo. For detailed instructions on how to get an SSH key on your computer, you can refer to this link.

CodeArts Req

CodeArts Req is an agile project management and collaboration service designed for software development teams. In this section, we will create a basic project and then proceed to manage it by adding a sprint plan and its corresponding work items. This will allow us to effectively track and organize the development process. Let’s get started!

Firstly, we need to create a sprint plan, and for that, our URI will be:

POST /v4/projects/{project_id}/iteration

As you can see, we will utilize the previously mentioned project_id. The request’s body should resemble the screenshot below, incorporating mandatory parameters such as begin_time, end_time, and name. (You can find these parameters in the CodeArts Req Documentation here.) The response will provide us with the iteration_id, which we will use later.

Creating a Sprint Plan

Then, we can create the work items that we will include in our sprint plan. The URI for this operation will be:

POST /v4/projects/{project_id}/issue

The request body must include parameters such as name, priority_id, and tracker_id. In some of the requests, we will also include optional parameters like iteration_id and parent_issue_id. These optional parameters help us manage the connection between work items and the sprint plan. You can refer to the screenshots below to see the operations I performed.

In this request, as it is an Epic and lacks any parent work item, we only send the mandatory parameters.

Creating a Work Item (Epic1)

Here, we need to send the parent_issue_id parameter, as we want to establish a connection between the Epic1 and Feature1 work items.

Creating a Work Item (Feature1)

For the three requests below, it’s important to include the iteration_id parameter, as we intend to associate these work items with the sprint plan we’ve created.

Creating a Work Item (Story1)
Creating a Work Item (Task1)
Creating a Work Item (Task2)

Here, as depicted in the 2 screenshots below, the work items and sprint plan have been successfully created on CodeArts Req according to our requirements.

Sprint Plan
Work Items

Furthermore, you have the option to utilize other URIs for updating or deleting items. For these actions and more, you can refer to the complete API list available in the CodeArts Req Documentation here.

CodeArts Repo

CodeArts Repo is a Git-based online code hosting service tailored for software developers. In this section, we will demonstrate how to create a repository using APIs. After that, we will clone the repository to our local PC using SSH, enabling us to make changes to the codebase easily. Once we’ve made the desired changes on our local PC, we will then submit them back to CodeArts Repo. This seamless process will facilitate collaborative software development and version control. Let’s proceed with the step-by-step demonstration!

Note: From this point onwards, I will utilize Huawei Cloud’s API Explorer instead of Postman. This platform proves to be an excellent resource for conducting API operations within its cloud services. For more information on API Explorer, you can refer to the link here.

Initially, we need to create a repository where we will upload or push our code. For this operation, the URI will be:

POST /v1/repositories

In the request body, we include the name and project_uuid of the repository that we intend to create.

Creating a Repository

As we aim to access the repository from our local computer, we need to establish a connection by adding the previously created SSH Key. To achieve this, we will utilize the following URI for the operation:

POST /v1/users/sshkey

In the request body, we will provide the key along with its title. This operation will enable the recognition of our local PC by Project1 and all its associated repositories.

Adding an SSH Key to the Project

Next, we require the SSH URL of the repository for accessing it. To achieve this, we will employ a request that provides information about all the repositories within the project. The URI for this operation is as follows:

GET /v1/projects/{project_uuid}/repositories

With the SSH URL duly noted, we now possess all the necessary elements to access the repository.

Getting Repository Information

Now, let’s establish a connection to the repository using SSH. I will be using Git Bash for these operations, and I give the operation log for you below. For further details, you can refer to the link provided here.

Firstly, we need to clone the repository to our local computer. To do this, we will utilize the SSH URL we obtained in the previous step.

git clone 'SSH URL of the repository'

Next, we can proceed to make the desired changes within the repository. In this example, I have copied the files from the Java Web Demo template into the folder.

Afterward, we can add the modified files to the repository and proceed to commit the changes.

git add .
git commit -m "First Commit"

Lastly, we push the repository to CodeArts Repo, completing our tasks here.

git push origin

Additionally, as depicted in the screenshot below, which showcases the CodeArts Repo user interface, the code we pushed to the repository is now present and ready for further action.

Repository1

CodeArts Check

CodeArts Check is a cloud-based management service that checks code quality. Developers can easily perform static code and security checks in multiple languages and obtain comprehensive quality reports. Here we will check the code we pushed to the repository earlier. Let’s do this on the steps below. (Actually, CodeArts automatically creates check, build, and deploy tasks after you create a repository; but here we will create a check task ignoring the one automatically created.)

In this section of the project, our initial step involves creating a check task using the following URI:

POST /v2/{project_id}/task

In the body of this request, we will include the parameters ‘git_url’ and ‘git_branch’ corresponding to the repository we intend to check. Additionally, we need to specify the programming language of the code and the rulesets we intend to apply. For instance, given that this is a Java Web Demo, we will utilize the Java and JavaScript rulesets. Importantly, we should make note of the ‘task_id’ provided in the response, as this will be essential for subsequent steps.

Creating a Check Task

Subsequently, we proceed to execute the check task established in the previous step. This can be achieved by utilizing the following URI:

POST /v2/tasks/{task_id}/run

In this request, there is no need to include a request body. If a status code of 200 is received, it signifies that the task has commenced, and we await its completion for a brief duration.

Running a Check Task

After waiting for a period, we can now access the check test records using the following URI:

GET /v2/{project_id}/tasks/{task_id}/checkrecord

No request body is required for this step as well, similar to the previous one. Once we receive a response, we can view the historical results associated with this task_id.

Check Task Records

Now that we have assessed the quality of our code, we can make necessary adjustments or proceed with building it based on the results.

Here, as depicted in the screenshot below, the check task is also visible in the CodeArts user interface, displaying the results as we obtained them.

Repository1 Check Task

👉Conclusion

In this article, we successfully accomplished the creation of a project on Req, the uploading of our code to Repo, and the evaluation of our code quality using Check. Throughout these steps, we solely relied on APIs and SSH, without utilizing the CodeArts user interface. This approach not only facilitated our understanding of API usage but also provided us with a deeper insight into the functionalities of CodeArts services. In my upcoming article, I will further explore the Build and deploy operations.

💁References

--

--