summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rwxr-xr-xicktool73
2 files changed, 70 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 3eec03d..91e2186 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Version 0.17+git, not yet released
----------------------------------
+* Add subommand `icktool status` which shows current status of every
+ pipeline in every project.
Version 0.17, released 2017-11-19
----------------------------------
diff --git a/icktool b/icktool
index 8a04fe1..8b89a84 100755
--- a/icktool
+++ b/icktool
@@ -102,9 +102,43 @@ class Icktool(cliapp.Application):
obj = json.loads(text)
self._prettyson(obj)
- def cmd_list_projects(self, args):
+ def cmd_status(self, args):
+ rows = []
+ projects = self._get_projects()
+ builds = self._get_builds()['builds']
+ for project in projects['projects']:
+ pipelines = project['pipelines']
+ for pipeline in pipelines:
+ build = self._get_latest_build(
+ project['project'], pipeline['name'], builds)
+ row = {
+ 'project': project['project'],
+ 'pipeline': pipeline['name'],
+ 'build_id': build['build_id'],
+ 'status': pipeline['status'],
+ 'log': build['log'],
+ }
+ rows.append(row)
+ self._pretty_table(rows, ['project', 'pipeline', 'status', 'log'])
+
+ def _get_projects(self):
rc = self._new_rc('/projects', 'project')
- self._prettyson(rc.list())
+ return rc.list()
+
+ def _get_builds(self):
+ rc = self._new_rc('/builds', 'build')
+ return rc.list()
+
+ def _get_latest_build(self, project_name, pipeline_name, builds):
+ latest = None
+ for build in builds:
+ if (build['project'] == project_name and
+ build['pipeline'] == pipeline_name):
+ latest = build
+ return latest
+
+ def cmd_list_projects(self, args):
+ self._prettyson(self._get_projects())
def cmd_create_project(self, args):
rc = self._new_rc('/projects', 'project')
@@ -190,8 +224,7 @@ class Icktool(cliapp.Application):
rc.delete(name)
def cmd_list_builds(self, args):
- rc = self._new_rc('/builds', 'build')
- self._prettyson(rc.list())
+ self._prettyson(self._get_builds())
def cmd_list_logs(self, args):
rc = self._new_rc('/logs', 'log')
@@ -214,7 +247,9 @@ class Icktool(cliapp.Application):
gen = TokenGenerator()
gen.set_cmd(cmd)
gen.set_scopes(scopes)
- return gen.new_token()
+ token = gen.new_token()
+ self.settings['token'] = token
+ return token
def _new_api(self):
token = self.settings['token'] or self._new_token()
@@ -235,6 +270,34 @@ class Icktool(cliapp.Application):
def _read_object(self):
return yaml.load(sys.stdin)
+ def _pretty_table(self, rows, columns):
+ headings = {
+ column: column
+ for column in columns
+ }
+
+ widths = {
+ column: 0
+ for column in columns
+ }
+
+ for row in [headings] + rows:
+ for column in columns:
+ widths[column] = max(widths[column], len(row[column]))
+
+ underlines = {
+ column: '-' * widths[column]
+ for column in columns
+ }
+
+ for row in [headings, underlines] + rows:
+ self.output.write(
+ '{}\n'.format(self._pretty_row(widths, row, columns)))
+
+ def _pretty_row(self, widths, row, columns):
+ parts = ['%*s' % (widths[c], row[c]) for c in columns]
+ return ' | '.join(parts)
+
class API: