dshoreman / servidor

A modern web application for managing servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace branch input with a dropdown

dshoreman opened this issue · comments

It'd be awesome if we could have some kind of dropdown menu that lists all the branches for the repo in Site Editor to avoid memorising them or typing them in. This consists of two parts:

Backend / API

We'll need a new endpoint that accepts the value from source_repo and returns a list of branches. The source repo should be validated using the same rules as when editing a Site.

To get the actual branches we can run git ls-remote --heads <repo_url> via exec(). We don't care about the commit SHAs, so everything before and including refs/heads/ can be stripped:

$ git ls-remote --heads https://github.com/dshoreman/servidor.git | sed 's^.*refs/heads/^^'
develop
master

Frontend

The source_branch input should be replaced with a SemanticUI Search Selection, which could also allow for setting a specific commit or tag in the future using the search field's value. To get data we'll need to add a listBranches or similar action to the Site VueX module, using axios to call the API.

If there are no branches it might be best to revert to a text input in case the repo hasn't been pushed to yet. The store action should be triggered both when the page loads and when the repo URL changes, otherwise we might end up using branches that don't exist on the repo we're saving.

Checklist

The tl;dr. Each one of these could be a separate PR.

  • Add an API endpoint that takes a repo URL and returns its branches as an array
  • Update the setSiteEditor mutation to load branches from the API endpoint
  • Replace the branch input with a sui-dropdown component
  • Make the dropdown filterable by typing partial branch names
  • Ensure the branch list is updated when the source repo is changed
  • Display a spinner when the branches list is being updated