Share this page

# Add SCM data

You can inject SCM (source code management) data into OpenText Software Delivery Management using the REST API. Then you can track commits and other relevant data such as repositories and branches, and perform code analysis.

Note: This method is a technical preview.

In this topic:

## Flow

You can inject SCM data directly using the API.

To inject SCM data using the API:

1. Authenticate and sign in as a user with the necessary permissions. For details, see Authentication.

2. Push the SCM data using either:

   - Pipeline context flow. SCM data is injected with the CI Job execution details, and the commits associated with the pipeline run. For details, see Push SCM data using the pipeline context flow.

   - Workspace context flow. SCM data is injected for the workspace input; the data is standalone without reference to the pipeline. For details, see Push SCM data using the workspace context flow.

   Tip:

   - We recommend using the pipeline context flow because test failure analysis, code coverage, and the vulnerability features are not supported in the workspace context flow.

   - If you push SCM data using both the pipeline context flow and the workspace context flow, data sent from the workspace context flow is ignored.

3. Check the status of the push, and get commit and branch data. For details, see Check results.

Back to top

## Push SCM data using the pipeline context flow

Use the PUT operation with a payload to create new SCM Data entities, like repositories, branches, and commits.

The unique commit identifier is parentRevId. If the revision ID is found in the context but for a different repository/branch, the commit is linked to the other repository.

Request syntax

The request syntax for injecting SCM information using the CI event flow is:

`PUT .../api/shared_spaces/space_id/scm-commits?instance-id='<instance_id>'&job-ci-id='<path_to_file>'&build-ci-id='<build_id>'`

When PUTing, specify the following:

- A query for identifying the pipeline run.

- A request body containing the JSON payload described below.

- The Content-Type header field, set to application/json.

- Optionally, the content can be compressed in gzip format. In this case, the Content-Encoding header field must be set to application/gzip.

The following table describes how to identify the corresponding pipeline run in request.

Item | Field
--- | ---
CI server ID | instance-id
Job name, such as Jenkins | job-ci-id
Build ID | build-ci-id

For details on the JSON payload in the request body, see JSON payload in the request body.

Back to top

## Push SCM data using the workspace context flow

You can inject SCM commits using the workspace context flow, instead of the pipeline context flow.

To push SCM data into a workspace using the workspace context flow, specify the workspace ID in the following format:

`field name workspace=<workspace_id>`

For details on the JSON payload in the request body, see JSON payload in the request body.

Note:

- Test failure analysis, code coverage, and vulnerability features are not supported for commits that were injected using the workspace context flow.

- You can set injection to one workspace only.

Back to top

## JSON payload in the request body

The payload in the request body describes the pipeline run or workspace that you want to update with SCM data.

You can specify more than one commit in the payload.

The payload uses the standard REST API syntax.

Example:

    [{
            "repository": {
                "type": "git",
                "url": " https://github.com/repository.git",
                "branch": "master"
            },
            "commits":
            [{
                    "user": "user",
                    "userEmail": "user@mail.com",
                    "time": "1586269223000",
                    "parentRevId": "e5358a5f1456aebbf5c436790179fe6b218def89",
                    "comment": "some comment",
                    "revId": "7583cc0704efd0ef96bbb4689a401d252adea821",
                    "changes": [{
                            "type": "edit",
                            "file": "src/…filePath/Example1.java",
                            "renameToFile": null,
                            "commitId": null
                        }
                    ]
                }, {
                    "user": "user",
                    "userEmail": "user@mail.com",
                    "time": "1586269223000",
                    "parentRevId": "e5358a5f1456aebbf5c436790179fe6b218def81",
                    "comment": "some comment",
                    "revId": "7583cc0704efd0ef96bbb4689a401d252adea822",
                    "changes": [{
                            "type": "edit",
                            "file": "src/…filePath/Example2.java",
                            "renameToFile": null,
                            "commitId": null
                        }
                    ]
                }
            ]
    }]

The following table describes the fields in the payload request body.

Field | Description
--- | ---
Repository | One element.
type | Tool type: “svn","git","starteam". Free text string.
url | URL to the SCM repository.
branch | Branch where commits were done.
Commits | Array.
parentRevId | Commit parentRevId, received from SCM tool.
revId | Commit revId, received from SCM tool.
comment | Commit comment, received from SCM tool.
time | Commit time, received from SCM tool.
userEmail | Email of the workspace user responsible for the commit. This field is used to identify the user. Optional.
user | User name.
Changes | Array of changes. Optional.
type | “edit”, “add”, “delete”. Free text string.
file | Changed file name.

Back to top

## Check results

If successful, return code 200 is returned.

Make sure that the SCM data has been pushed correctly into OpenText Software Delivery Management.

1. Check the response for errors that may have occurred.

   In addition to a success or error code, a background task ID that tracks the commits injection process is also returned.

2. Check if the commits exist in OpenText Software Delivery Management. For details, see Track commits to your SCM system.

   Workspace context only: Tracking commits that were added are shown in dashboards and in the Team Backlog > Development tab only.

Get commit and branch data

You can see existing SCM commits and their IDs using a GET operation:

`GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/scm_commits`

See Examples.

You can see existing SCM branches and their IDs using a GET operation:

`GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/scm_repositories`

Back to top

## Examples

For example, we have in the request:

    Example: GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/scm_commits/1213269?fields=creation_time,client_lock_stamp,stories,version_stamp,commit_time,revision,workspace_id,repositories,name,workspace_user,risk,comment,last_modified,user,email

Without workspace user, repositories, and stories, the response is:

    Example: GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/scm_commits/1213269?fields=creation_time,client_lock_stamp ,version_stamp,commit_time,revision,workspace_id,name,risk,comment,last_modified,user,email

    {
        "type": "scm_commit",
        "last_modified": "2020-08-22T22:31:25Z",
        "revision": "53e564566a75fcc073a5ed0dd71bad0f0f588855",
        "creation_time": "2020-08-20T08:34:10Z",
        "user": "userName",
        "risk": false,
        "comment": "user story #1053020. user story 11111111",
        "commit_time": "2020-08-20T08:33:06Z",
        "name": "commit name",
        "workspace_id": 33006,
        "id": "1213269",
        "version_stamp": 14,
        "client_lock_stamp": 1
    }

With the SCM data, the response is:

    Example: {
        "type": "scm_commit",
        "last_modified": "2020-08-22T22:31:25Z",
        "revision": "53e564566a75fcc073a5ed0dd71bad0f0f588855",
        "creation_time": "2020-08-20T08:34:10Z",
        "user": "evgene.lock",
        "risk": false,
        "comment": "user story #1053020. user story 11111111",
        "commit_time": "2020-08-20T08:33:06Z",
        "name": "commit name",
        "workspace_id": 33006,
        "id": "1213269",
        "version_stamp": 14,
        "client_lock_stamp": 1,
        "stories": {
                "total_count": 1,
                "data": [{
                               "type": "work_item",
                               "id": "1053020",
                               "name": "US1",
                               "subtype": "story"
                       }
                ]
        },
        "repositories": {
                "total_count": 1,
                "data": [{
                               "type": "scm_repository",
                               "scm_source_view": null,
                               "scm_type": 2,
                               "scm_diff": null,
                               "workspace_id": 33006,
                               "branch": "master",
                               "id": "324004",
                               "name": "repository.git:master",
                               "url": "https://github.com/repository.git"
                       }
                ]
        },
        "workspace_user": {
                "type": "workspace_user",
                "id": "117001",
                "workspace_id": 33006,
                "activity_level": 0,
                "full_name": "User Name",
                "name": "userName@mail.com"
        }
    }

Back to top

See also:

- API access
- Track commits to your SCM system

https://admhelp.microfocus.com Software Delivery Management 8942
Tips to improve your search results... OpenText™ Software Delivery Management Help Center OpenText™ Software Delivery Management Help 26.1 All View Local Help Center View Online Help Center Version: