#!/usr/bin/python2.7
#
# Trigger to post changelist info on submission to a Slack channel
# Add this trigger to your Perforce server:
#
# slack change-content //... "/path/to/slack_trigger.py %change% %serverport%"
#
import requests
import sys
import json
import subprocess
# Required
p4user = "your p4 user"
slackbot_user = "your slack bot user"
webhook_url = 'https://hooks.slack.com/services/your_unique_key'
# Optional: set swarm_url if you want to use Swarm links
swarm_url = ""
def linkify(desc, num):
if len(swarm_url) > 0:
result = desc.replace("Change " + num, ">>><" + swarm_url + "/changes/" + num + "|Change " + num + ">", 1)
return result
else:
return desc
if len(sys.argv) > 1:
change = str(sys.argv[1])
port = str(sys.argv[2])
output = subprocess.check_output("p4 -p " + port + " -u " + p4user + " describe -s -m5 " + change, shell=True)
print(output)
description = linkify(output, change)
data = payload={"text":description, "username":slackbot_user}
requests.post(webhook_url, data=json.dumps(data))
else:
print("No argument given.")
# |
Change |
User |
Description |
Committed |
|
#1
|
18397 |
Liz Lam |
Adding Slack trigger. |
|
|