runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.83k stars 1.06k forks source link

Feature: API for listing locks and jobs #4896

Open ilyaluk opened 2 months ago

ilyaluk commented 2 months ago

Community Note


Describe the user story

I'm writing a small tool to visualize plans from Atlantis (if there are dozens of them, it's inconvenient to view in PR comments). It needs to have access to list of locks and jobs to correctly show plan statuses (e.g. whether stack is locked by some other PR, or errored) and include output log links. Currently, I'm using raw access to Atlantis bbolt DB for locks and parsing HTML of / for jobs. This is inconvenient and unstable.

Describe the solution you'd like

Add two endpoints: GET /api/locks GET /api/jobs

They will return JSON-encoded data from locking.Locker.List() and jobs.ProjectCommandOutputHandler.GetPullToJobMapping()

The solution looks pretty easy, and I'd be happy to contribute a PR.

Describe the drawbacks of your solution

This way some previously inner APIs are exposed, and someone might base their expectations about these APIs and data formats that they return. This might complicate future refactorings.

Describe alternatives you've considered

As I mentioned earlier, parsing HTML or using raw DB access, but that is not good in the long run. Alternatively, job log URLs could be retrieved from VCS, but it's not universal.

GMartinez-Sisti commented 1 week ago

Hi @ilyaluk , I think this is a great idea. I have some automation that would benefit from this too.

Would you like to contribute this?