Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to enable a hook on a repository as inherited from project scope

Maik Ebert August 2, 2018

I want to enable a hook via REST api for a repository in the inherited-from-project state.

How can I do this via REST api?

 

When I call

/rest/api/1.0/projects/some/repos/another/settings/hooks/com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook/enabled

I get

{
"details": {
"key": "com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook",
"name": "Webhook to Jenkins for Bitbucket Server",
"type": "POST_RECEIVE",
"description": "Webhook for notifying a configured endpoint of changes to this repository.",
"version": "4.4.2",
"configFormKey": "com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook-config-form",
"scopeTypes": [
"REPOSITORY",
"PROJECT"
]
},
"enabled": true,
"configured": true,
"scope": {
"type": "PROJECT",
"resourceId": 534
}
}

 

I want to set now that scope=type:PROJECT via REST api if its in any other state.

I could not find the needed http call to do so.

 

Please help.

Thanks in advance,

Maik

1 answer

1 accepted

0 votes
Answer accepted
Dick
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 2, 2018

Hi Maik!

Thanks for reaching out. Can you please help me understand a bit better what you're trying to achieve?

You are trying a PUT request on:

/rest/api/1.0/projects/some/repos/another/settings/hooks/com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook/enabled

Correct?

That endpoint is specifically for enabling a hook at the repository level. Therefore, I expect the result to have scope=type:REPOSITORY, not scope=type:PROJECT as your JSON indicates. Can you verify this?

To have the hook inherit the project scope, you need to remove the setting at the repository level (if it exists), by calling

DELETE /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}

Validate the settings are inherited properly by calling

GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}

You should then see scope=type:PROJECT for that hook.

See the documentation on these endpoints here.

Edit: To enable a hook at the project level (scope=type:PROJECT), use the following endpoint:

PUT /rest/api/1.0/projects/{projectKey}/settings/hooks/{hookKey}/enabled

Note: if a hook has settings at the repository level, that will have priority.

See documentation here

Maik Ebert August 3, 2018

Hi Dick,

perfect, thank you!

That was the missing piece of information.

Maik

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events