Semaphoreapp
A Ruby client for the Semaphore API.
Installation
Add this line to your application's Gemfile:
gem 'semaphoreapp'
And then execute:
$ bundle
Or install it yourself as:
$ gem install semaphoreapp
Configuration
To use the Semaphore API, you need an auth_token. You can find your token through the Semaphore web interface.
To configure the gem with your token, add a line such as:
Semaphoreapp.auth_token = 'Yds3w6o26FLfJTnVK2y9'The token will be cached, so you will only need to set it once.
Usage
Projects
To get all the projects associated with your auth token:
projects = Semaphoreapp::Project.allTo get a specific project (based on its name):
project = Semaphoreapp::Project.find_by_name('testapp-sphinx')Once you have a project, you can get all its branches:
project.get_branchesYou can also get all its servers:
project.get_serversNote that, due to the way the API works, the following call will return all the branch statuses for a given project:
project.branchesBranches
Note that all the class methods for Branch require the hash id of the project to be passed in as a parameter (3f1004b8343faabda63d441734526c854380ab89 in the examples below).
To get a specific branch (based on its name):
branch = Semaphoreapp::Branch.find_by_name('3f1004b8343faabda63d441734526c854380ab89', 'master')Once you have a branch, you can get its current status:
branch.get_statusor its build history:
branch.get_buildsBuilds
Note that the following examples assume you already have a build object, which you can obtain by doing something like:
build = Semaphoreapp::Branch.find_by_name('3f1004b8343faabda63d441734526c854380ab89', 'master').get_builds.firstTo get the build information:
build.get_informationThis will return a BuildInformation instance which in turn contains a list of Commit instances.
To get the build log:
build.get_logThis will return a BuildLog instance which in turn contains a list of Thread instances. Each of the threads contains a list of Command instances.
Servers
Note that all the class methods for Server require the hash id of the project to be passed in as a parameter (3f1004b8343faabda63d441734526c854380ab89 in the examples below).
To get a specific server (based on its name):
server = Semaphoreapp::Server.find_by_name('3f1004b8343faabda63d441734526c854380ab89', 'staging')Once you have a server, you can get its current status:
server.get_statusor its deploy history:
server.get_deploysDeploys
Note that the following examples assume you already have a deploy object, which you can obtain by doing something like:
deploy = Semaphoreapp::Server.find_by_name('3f1004b8343faabda63d441734526c854380ab89', 'staging').get_deploys.firstTo get the deploy information:
deploy.get_informationThis will return a DeployInformation instance which in turn contains a Commit instance.
To get the deploy log:
deploy.get_logThis will return a DeployLog instance which in turn contains a list of Thread instances. Each of the threads contains a list of Command instances.
Object model
The gem uses classes to represent objects returned by API calls. The classes are:
-
Project: a project Semaphore is running CI for. It may have manyBranchStatusobjects. -
BranchStatus: the status of a branch in a project. It may have aCommitobject. -
Branch: a branch in a project. -
Build: a CI build. It may have aCommitobject. -
Commit: a Git commit. -
BuildInformation: the information related to a build. It may have manyCommitobjects. -
BuildLog: the log for a build. It may have manyThreadobjects. -
Thread: a build thread. It may have manyCommandobjects. -
Command: a command in a build thread. -
Server: a server a project can be deployed to. -
ServerStatus: the status of a server in a project. It may have aCommitobject. -
Deploy: a deploy to a server. It may have aCommitobject. -
DeployInformation: the information related to a deploy. It may have aCommitobject. -
DeployLog: the log for a deploy. It may have manyThreadobjects.
Tests
To run all the specs for this project:
$ rakeContributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request