GetCompare - Query code comparison content

Updated at:

Retrieves code comparison content between branches, commits, or tags. The from and to order follows Git command-line convention, which is the reverse of the UI display order. Ensure you compare items of the same type, such as branch to branch or commit to commit.

Applicable editions

Central edition, Region edition

Endpoints and authorization information

  • Obtain the endpoint: Replace {domain} in the API request syntax.

  • Obtain a personal access token.

  • Obtain organizationId: Required for Central edition only. Go to the Basic Information page in the Organization Management console to obtain your organization ID.

Product

Resource

Required permission

Code Management

Code comparison

Read-only

Request syntax

Central edition

GET https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/compares

Region edition

GET https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/compares

Request headers

Parameter

Type

Required

Description

Example value

x-yunxiao-token

string

Yes

Personal access token.

pt-0fh3****0fbG_35af****0484

Request parameters

Parameter

Type

Location

Required

Description

Example value

organizationId

string

path

  • Yes: Central edition

  • No: Region edition

Organization ID.

60d54f3daccf2bbd6659f3ad

repositoryId

string

path

Yes

Repository ID or URL-encoded full path.

2813489 or 60de7a6852743a5162b5f957%2FDemoRepo

from

string

query

Yes

Commit SHA, branch name, or tag name.

master

to

string

query

Yes

Commit SHA, branch name, or tag name.

dev_branch

sourceType

string

query

No

Valid values: branch, tag. Omit this parameter for commit comparisons. For branch comparisons, specify branch (optional if no branch or tag shares the same name). For tag comparisons, specify tag. If a branch and a tag share the same name, you must explicitly specify branch or tag.

branch

targetType

string

query

No

Valid values: branch, tag. Omit this parameter for commit comparisons. For branch comparisons, specify branch (optional if no branch or tag shares the same name). For tag comparisons, specify tag. If a branch and a tag share the same name, you must explicitly specify branch or tag.

branch

straight

string

query

No

Controls merge-base behavior. false (default): uses merge-base. true: skips merge-base.

false

Request examples

Central edition

curl -X 'GET' \
  'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/2813489%E6%88%96%E8%80%8560de7a6852743a5162b5f957%2FDemoRepo/compares?from=master&to=dev_branch&sourceType=branch&targetType=branch&straight=false' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484'

Region edition

curl -X 'GET' \
  'https://{domain}/oapi/v1/codeup/repositories/2813489%E6%88%96%E8%80%8560de7a6852743a5162b5f957%2FDemoRepo/compares?from=master&to=dev_branch&sourceType=branch&targetType=branch&straight=false' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484'

Response parameters

Parameter

Type

Description

Example value

-

object

commits

array

List of differing commits.

-

object

authorEmail

string

Author email address.

username@example.com

authorName

string

Author name.

codeup-name

authoredDate

string

Authoring timestamp.

2024-10-05T15:30:45Z

committedDate

string

Commit timestamp.

2024-10-05T15:30:45Z

committerEmail

string

Committer email address.

username@example.com

committerName

string

Committer name.

codeup-name

id

string

Commit ID.

6da8c14b5a9102998148b7ea35f96507d5304f74

message

string

Commit message.

commit message detail

parentIds

array[string]

Parent commit IDs.

["3fdaf119cf76539c1a47de0074ac02927ef4c8e1"]

shortId

string

Short commit ID.

6da8c14b

title

string

Title (first line of the commit message).

commit msg title

webUrl

string

Page access URL.

http://exmaple.com/example_repo/commit/commit_sha

diffs

array

File differences.

-

object

aMode

string

File mode of the old file, including file type and permissions.

0

bMode

string

File mode of the new file, including file type and permissions.

100644

deletedFile

boolean

Indicates whether the file was deleted.

false

diff

string

Diff content.

--- /dev/null\n+++ b/asda\n@@ -0,0 +1 @@\n+asdasd\n\ No newline at end of file\n

isBinary

boolean

Indicates whether the file is a binary file.

false

newFile

boolean

Indicates whether the file is new.

true

newId

string

Git object ID of the new file.

9118d6c90d0d80f906e70baf6af04a50ff660d7b

newPath

string

New file path.

src/test/main.java

oldId

string

Git object ID of the old file.

0000000000000000000000000000000000000000

oldPath

string

Old file path.

src/test/main.java

renamedFile

boolean

Indicates whether the file was renamed.

false

Response example

{
    "commits": [
        {
            "authorEmail": "username@example.com",
            "authorName": "codeup-name",
            "authoredDate": "2024-10-05T15:30:45Z",
            "committedDate": "2024-10-05T15:30:45Z",
            "committerEmail": "username@example.com",
            "committerName": "codeup-name",
            "id": "6da8c14b5a9102998148b7ea35f96507d5304f74",
            "message": "commit message detail",
            "parentIds": ["3fdaf119cf76539c1a47de0074ac02927ef4c8e1"],
            "shortId": "6da8c14b",
            "title": "commit msg title",
            "webUrl": "http://exmaple.com/example_repo/commit/commit_sha"
        }
    ],
    "diffs": [
        {
            "aMode": "0",
            "bMode": "100644",
            "deletedFile": false,
            "diff": "--- /dev/null\n+++ b/asda\n@@ -0,0 +1 @@\n+asdasd\n\\ No newline at end of file\n",
            "isBinary": false,
            "newFile": true,
            "newId": "9118d6c90d0d80f906e70baf6af04a50ff660d7b",
            "newPath": "src/test/main.java",
            "oldId": "0000000000000000000000000000000000000000",
            "oldPath": "src/test/main.java",
            "renamedFile": false
        }
    ]
}

Error codes

For API error codes, see Error Code Center.