woodpecker icon indicating copy to clipboard operation
woodpecker copied to clipboard

[API] /api/user/repos include last build status

Open nitn3lav opened this issue 3 years ago • 1 comments

To show the current build status on the repos page it is necessary to have some basic information about the latest build of each repo. While it would generally be possible to retrieve this info using the GET /api/repos/<owner>/<repo>/builds endpoint this would lead to a unnecessarily large number of requests. Therefore I propose to directly add this data to GET /api/user/repos. I can currently think of these options to do so:

  1. add info about the last build:
[
    {
        "id": 5,
        "owner": "test",
        "name": "123",
        "full_name": "test/123",
        "link_url": "https://git.example.com/test/123",
        // new:
        "last_build": {
            "id": 107,
            "number": 19,
            "author": "test",
            "event": "push",
            "status": "success",
            "enqueued_at": 1643933634,
            "created_at": 1643933634,
            "started_at": 1643938125,
            "finished_at": 1643939241,
            "commit": "7fe7b02400c1c598a3f49b65c5693e4e41554056",
            "branch": "main",
            "message": "commit message",
            "timestamp": 1643933633,
            "author_avatar": "https://git.example.com/avatars/fa93386cdc60183ae3a861c45170bc6a",
            "link_url": "https://git.piored.de/vidre/transcoding-server/commit/7fe7b02400c1c598a3f49b65c5693e4e41554056",
            "changed_files": [
                "testfile-1"
            ],
            ...
        },
        ...
    },
    ...
]
  1. alternatively this could be the last build on the default barnch (usually master or main)

  2. add an array of the latest builds for each branch:

[
    {
        "id": 5,
        "owner": "test",
        "name": "123",
        "full_name": "test/123",
        "link_url": "https://git.example.com/test/123",
        // new:
        "last_builds": [
            {
                "id": 107,
                "number": 19,
                "author": "test",
                "event": "push",
                "status": "success",
                "enqueued_at": 1643933634,
                "created_at": 1643933634,
                "started_at": 1643938125,
                "finished_at": 1643939241,
                "commit": "7fe7b02400c1c598a3f49b65c5693e4e41554056",
                "branch": "main", // dafault branch
                "message": "commit message",
                "timestamp": 1643933633,
                "author_avatar": "https://git.example.com/avatars/fa93386cdc60183ae3a861c45170bc6a",
                "link_url": "https://git.piored.de/vidre/transcoding-server/commit/7fe7b02400c1c598a3f49b65c5693e4e41554056",
                "changed_files": [
                    "testfile-1"
                ],
                ...
            },
            // if option 5 is chosen, this is only included if the last build was not on the default branch
            {
                "id": 107,
                "number": 19,
                "author": "test",
                "event": "push",
                "status": "success",
                "enqueued_at": 1643933634,
                "created_at": 1643933634,
                "started_at": 1643938125,
                "finished_at": 1643939241,
                "commit": "a6e350241cc1c598ada90b65cee8f3e4e41abf3f7",
                "branch": "new-feature-branch", // some branch other than the default `main`
                "message": "commit message",
                "timestamp": 1643933633,
                "author_avatar": "https://git.example.com/avatars/fa93386cdc60183ae3a861c45170bc6a",
                "link_url": "https://git.piored.de/vidre/transcoding-server/commit/7fe7b02400c1c598a3f49b65c5693e4e41554056",
                "changed_files": [
                    "testfile-2"
                ],
                ...
            },
            ...
    },
    ...
]
  1. a map with the branch as key could be used instead of an array:
[
    {
        "id": 5,
        "owner": "test",
        "name": "123",
        "full_name": "test/123",
        "link_url": "https://git.example.com/test/123",
        // new:
        "last_builds": {
            "main": { // default branch
                "id": 107,
                "number": 19,
                "author": "test",
                "event": "push",
                "status": "success",
                "enqueued_at": 1643933634,
                "created_at": 1643933634,
                "started_at": 1643938125,
                "finished_at": 1643939241,
                "commit": "7fe7b02400c1c598a3f49b65c5693e4e41554056",
                "branch": "main", // dafault branch
                "message": "commit message",
                "timestamp": 1643933633,
                "author_avatar": "https://git.example.com/avatars/fa93386cdc60183ae3a861c45170bc6a",
                "link_url": "https://git.piored.de/vidre/transcoding-server/commit/7fe7b02400c1c598a3f49b65c5693e4e41554056",
                "changed_files": [
                    "testfile-1"
                ],
                ...
            },
            // if option 5 is chosen, this is only included if the last build was not on the default branch
            "new-feature-branch": { // some branch other than the default `main`
                "id": 107,
                "number": 19,
                "author": "test",
                "event": "push",
                "status": "success",
                "enqueued_at": 1643933634,
                "created_at": 1643933634,
                "started_at": 1643938125,
                "finished_at": 1643939241,
                "commit": "a6e350241cc1c598ada90b65cee8f3e4e41abf3f7",
                "branch": "new-feature-branch", // some branch other than the default `main`
                "message": "commit message",
                "timestamp": 1643933633,
                "author_avatar": "https://git.example.com/avatars/fa93386cdc60183ae3a861c45170bc6a",
                "link_url": "https://git.piored.de/vidre/transcoding-server/commit/7fe7b02400c1c598a3f49b65c5693e4e41554056",
                "changed_files": [
                    "testfile-2"
                ],
                ...
            },
            ...
    },
    ...
]
  1. Instead of including the latest build status for every branch it would also be possible to only include the info for the default branch and if applicable the latest build on a non-default branch. This could reduce data usage for repos with many branches.

Options 3, 4 and 5 would allow users to select in the settings if they want to see the status of the latest build or the latest build on the default branch (master or main).

nitn3lav avatar Feb 04 '22 19:02 nitn3lav