RepositoryHookContext is empty

Paul Christensen June 18, 2013
I'm trying to work through a pre-recieve hook. I've got it executing and displaying messages to the user's console, but the RepositoryHookContext is empty. I have appropriate data in my RefChange collection, but nothing in the RepositoryHookContext, and I'm a little stumped. I've gone over the tutorials and searched around, and I'm not finding anything that explains what I might be missing.

8 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
anil kumar March 11, 2014

Hi,

I'm not able to see the output in my git console after doing

git push http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.git

I did SDK setup and run it properly.

I got stash console and I able to see the commited messages there.

I enabled the hook in my project repo settings

Everything is working fine but want to see the output after pushing,

Added this print statement at start line in my hook class of public boolean onReceive()

hookResponse.out().println("=============================================== check check check ==========================================");

So can anyone suggest how to get that print statement in client console/git

or where can i find the print statements.

Thanks in advance

Anil

0 votes
Paul Christensen June 18, 2013

Ok, I was misunderstanding it. It's details about the commits that I'm after. Thanks. I think I'm on the right track now.

0 votes
Paul Christensen June 18, 2013

--clicked the wrong button. unable to delete.--

0 votes
jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 18, 2013

The Collection of RefChanges contains all the information for the push. getRefId() will give you the name of the branch, getFromHash() will give you the original commit hash and getToHash() will give you the new commit hash. The Settings is for per repository configuration which is configured via the repository hooks admin screens. If you need more information (for instance information about the commits being pushed, or the contents of the files) you should call to HistoryService and ContentService using the approriate commit hashes

0 votes
Paul Christensen June 18, 2013

maybe I'm misunderstanding what that object is. I've created a hook, and enabled it in my repository. When I do a push I thought the settings contained an object holding details about my push, so for example the refId pulled from my refChanges object is "refs/heads/master" for the specific commit. I would expect context.getSettings().getString("ref-id") to give me the name of the branch that I'm performing the push against.

Am I misunderstanding what the Settings object is?

0 votes
jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 18, 2013

So you have saved some settings for the repository you are pushing to via the hooks UI and they aren't being reflected in the settings object you are being passed? What settings are you expecting?

0 votes
Paul Christensen June 18, 2013

(updated to add the full method)

sorry if a double post. My previous comment seems to have disappeared.

No, the object isn't null, and the Settings object doesn't appear to be null either. The following yields an empty Map:

Settings settings = context.getSettings();

Map<String, Object> settingsMap = settings.asMap();

public boolean onReceive(@Nonnull RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse){

hookResponse.out().println("Hello. Thank you for pushing your code. Have a nice day.");

for(RefChange change : refChanges){

hookResponse.out().println(change.getRefId());

hookResponse.out().println(change.getType().name());

}

Settings settings = context.getSettings();

Map<String, Object> settingsMap = settings.asMap();

hookResponse.out().println("Settings size: " + settingsMap.size());

for(Object key : settingsMap.values()){

hookResponse.out().println(key.toString());

}

hookResponse.out().println(context.getSettings().getString("ref-id"));

return true;

}

0 votes
jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 18, 2013

Can you clarify what you mean by RepositoryHookContext being empty. Is it null? is the repository/settings null? Does the settings contain none of the configurations you have saved for your hook?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events