publishing with status feedback
This commit is contained in:
parent
5ecd33d853
commit
63fc5a49ce
58
fih.py
58
fih.py
@ -105,6 +105,22 @@ Again, after setting the headline status you must: **@FIH PUBLISH**
|
||||
else:
|
||||
return "Invalid command token."
|
||||
|
||||
|
||||
def exec_to_message( cmdline ):
|
||||
results = "`" + cmdline + "`:\n\n"
|
||||
process = subprocess.Popen( cmdline, shell = True, cwd = app.config[ "STATUS_ROOT" ], stdout = subprocess.PIPE, stderr = subprocess.PIPE )
|
||||
|
||||
stdout = strip_progress( strip_ansi( process.stdout.read().decode( 'ascii', 'ignore' ) ) )
|
||||
if stdout:
|
||||
results += "\n\n```\n" + stdout.replace( "```", "` ` `" ) + "```\n"
|
||||
stderr = strip_progress( strip_ansi( process.stderr.read().decode( 'ascii', 'ignore' ) ) )
|
||||
if stderr:
|
||||
results += "\n\n```\n" + stderr.replace( "```", "` ` `" ) + "```\n"
|
||||
if not stdout and not stderr:
|
||||
results += '_no output_\n'
|
||||
return results
|
||||
|
||||
|
||||
@app.route( '/mattermost/fih', methods = [ 'POST' ] )
|
||||
def mattermost_fih():
|
||||
# text: @FIH PUBLISH
|
||||
@ -124,24 +140,34 @@ def mattermost_fih():
|
||||
cmd = request.form[ 'text' ].strip().split()[ 1 ].upper()
|
||||
|
||||
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
||||
'message': "Executing " + cmd + "...",
|
||||
'message': "### Executing `" + cmd + "`...",
|
||||
} )
|
||||
|
||||
if cmd == "PUBLISH":
|
||||
for push_to in app.config[ "GROW_DEPLOY_TO" ]:
|
||||
cmdline = app.config[ "GROW_BIN" ] + " deploy -f " + push_to
|
||||
results = "`" + cmdline + "`:\n\n```\n"
|
||||
|
||||
process = subprocess.Popen( cmdline, shell = True, cwd = app.config[ "STATUS_ROOT" ], stdout = subprocess.PIPE, stderr = subprocess.PIPE )
|
||||
|
||||
results += strip_progress( strip_ansi( process.stdout.read().decode( 'ascii', 'ignore' ) ) ).replace( "```", "` ` `" )
|
||||
results += "```\n"
|
||||
stderr = strip_progress( strip_ansi( process.stderr.read().decode( 'ascii', 'ignore' ) ) )
|
||||
if stderr:
|
||||
results += "\n\n```\n" + stderr.replace( "```", "` ` `" ) + "```\n"
|
||||
|
||||
for pull_from in app.config[ "MERCURIAL_PUSH_TO" ]:
|
||||
cmdline = app.config[ "MERCURIAL_BIN" ] + " pull " + pull_from
|
||||
message = exec_to_message( cmdline )
|
||||
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
||||
'message': results,
|
||||
'message': message,
|
||||
} )
|
||||
|
||||
cmdline = app.config[ "MERCURIAL_BIN" ] + " merge"
|
||||
message = exec_to_message( cmdline )
|
||||
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
||||
'message': message,
|
||||
} )
|
||||
|
||||
cmdline = app.config[ "MERCURIAL_BIN" ] + " commit -m 'merge from " + pull_from + "'"
|
||||
message = exec_to_message( cmdline )
|
||||
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
||||
'message': message,
|
||||
} )
|
||||
|
||||
for deploy_to in app.config[ "GROW_DEPLOY_TO" ]:
|
||||
cmdline = app.config[ "GROW_BIN" ] + " deploy -f " + deploy_to
|
||||
message = exec_to_message( cmdline )
|
||||
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
||||
'message': message,
|
||||
} )
|
||||
|
||||
elif cmd == "START":
|
||||
@ -167,6 +193,10 @@ def mattermost_fih():
|
||||
else:
|
||||
return "WTF command?"
|
||||
|
||||
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
||||
'message': "### Finished `" + cmd + "`!",
|
||||
} )
|
||||
|
||||
return "OK"
|
||||
else:
|
||||
return "Invalid command token."
|
||||
|
Loading…
x
Reference in New Issue
Block a user