2

The snippet of this p4python code gets the perforce description and removes the square brackets mentioned in the description. I am planning to make this script called during the change-commit trigger to replace the CL description before even submitting the change. Not sure what's wrong, but the trigger doesnt take my new change description.. Has anyone tried doing this using the p4python? Any hints highly appreciated

describe = p4.run('describe', changeList)
print describe

description = describe[0].get('desc')
print description

description = description.replace('[', '')
description = description.replace(']', '')
print description

First describe prints

[{'status': 'pending', 'changeType': 'public', 'rev': ['21'], 'client': 'workspace1', 'user': 'username', 'time': '1432010818', 'action': ['edit'], 'type': ['text'], 'depotFile': ['//depot/repo/Vagrantfile'], 'change': '12345', 'desc': '[ABC-789] testfile commit'}]

First description prints

[ABC-789] testfile commit

Second description removes the square brackets

ABC-789 testfile commit
thunderbird
  • 121
  • 2
  • 10

2 Answers2

1

Is 'change-commit trigger' a typo? The change-commit trigger is called after the change is completely submitted, and can't make any modifications to it.

If you want to alter the changelist during the submit process, you need to use a change-submit or change-content trigger.

Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
  • Thanks for correcting Bryan.. you sre right.. i meant change-content – thunderbird May 19 '15 at 14:10
  • You should be able to alter the changelist description during a change-commit trigger. It won't be enough just to alter your 'description' variable in your Python program, though, and it won't be enough to print the updated description to stdout. You'll need to run a 'change -i' command with the change spec modified to contain the revised changelist description (but the rest of the changelist spec unchanged). – Bryan Pendleton May 19 '15 at 19:45
1

Since you mean during change-submit/content trigger, here's what I do:

details = p4.fetch_change(changelistNumber)
description = details['Description']

# Make changes to description

details[descriptionKey] = description
p4.save_change(details)