Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

trying to write a bitbucket pre-receive hook in groovy to run pylint or other test Edited

Hi,

I'm creating a groovy script which I've set as a pre-receive hook so as to run pylint on any .pp files and fail when the score is too low.

 

I set the hook at a URL like this one:

https://mybitbucketserver.example.com/plugins/servlet/scriptrunner/builtin?section=prehooks#

 

I've found lots of snippets of groovy code but I can't find a way to get a list of the actual files being committed...

I've run out of ideas trying random things, and am hoping someone can help. Any help at all would be gratefully received.

 

 

output when you do a git push

remote:
remote: =====================================================================
remote: pmansfield testing pre-commit hook
remote: repository name: paulm
remote: refChange type: refs/heads/master
remote: commit message: DEVOPS-2744 testing 25
remote: hello pmansfield
remote: =====================================================================
remote:

 

===groovy script===

import com.atlassian.bitbucket.content.Change
import com.atlassian.bitbucket.content.ChangeSummary
import com.atlassian.bitbucket.hook.HookResponse
import com.atlassian.bitbucket.repository.RefChange
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.user.ApplicationUser
import com.atlassian.bitbucket.user.Person

import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketCannedScriptUtils

def msg = new StringBuilder()
msg << "pmansfield testing pre-commit hook\n".toString()


def repository = repository as Repository
msg << "repository name: $repository.name \n".toString()


// DOESNT WORK stuff from ChangeSummary
//def changeSummary = changeSummary as Collection<ChangeSummary>

// DOESNT WORK stuff from Changes
//def changes = changes as Collection<Changes>
//for (change in changes) {
// msg << "change path: ${change.getPath()}\n".toString()
//}

// stuff from RefChange
def refChanges = refChanges as Collection<RefChange>
for (refChange in refChanges) {
msg << "refChange type: ${refChange.refId}\n".toString()
}

def commits = refChanges.getCommits(repository)
for (commit in commits) {
msg << "commit message: ${commit.getMessage()}\n".toString()
}

def authors = refChanges.getCommitAuthors(repository)
for (author in authors) {
msg << "hello $author.name \n".toString()
}



def hookResponse = hookResponse as HookResponse
hookResponse.out().write BitbucketCannedScriptUtils.wrapHookResponse(msg)

return true

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

75 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you