Add missing actions and data to Environments and Deployments APIs

Problem

Review apps are short lived by definition. Unfortunately, stale branches are ubiquitous (gitlab-ce has ~1,600). Keeping all as review apps would is already a burden for us. It's not possible to write a script because

Proposal

We want to write a script that periodically deletes old environments. However, it's not possible to implement it because Environments and Deployments APIs don't provide enough information.

environments = get "/projects/#{project_id.urlencode}/environments"
environments.each do |environment|
  next unless environment.available?
  deployment = get "/projects/#{project_id.urlencode}/deployments/#{environment.deployment_id.urlencode}"
  next if deployment.created_at >= 2.weeks.ago
  next if deployment.deployable.name != 'reviewapp-deploy' # VERY IMPORTANT! We only want to delete review apps, right?!
  post "/projects/#{project_id.urlencode}/environments/#{environment.id.urlencode}/stop"
end

Missing API functionality to be added

Status: available or stopped.

  • Endpoint /projects/:id/environments
  • Access the state field from the API
  • When the model is instantiated, state machine helper methods are available available?, stopped?

Deployment ID of the current deployment

Add missing API end-point (Rails: def show)

Links / references

~"feature proposal" ~"CI/CD" ~kubernetes

@ayufan @markglenfletcher @markpundsack @bikebilly @victorwu

Edited by Damian Nowak