- Print
- PDF
Managing webhook
- Print
- PDF
Available in Classic and VPC
Webhooks provide post-processing of multiple events that occur in the SourceCommit repository. By connecting to the Cloud Functions service in NAVER Cloud Platform or by connecting a specific URL to your webhook, you can receive event data to process business logics.
The webhook function is only available in the South Korea region.
You can utilize webhooks in various ways as follows:
- Connect CI/CD to SourceBuild, SourceDeploy, and SourcePipeline by detecting changes that occur in codes
- Run post-processing logics for repository events without managing a Proxy Server by connecting to Cloud Functions service triggers
- Reduce code review time through notifications of commit push or pull request creation
- Instantly receive File Safer malware scan results
- Instantly receive file lock/unlock status through LFS
Managing webhook
To use a webhook, first create a webhook by specifying a connection target to deliver an event to when the webhook is called.
Creating webhook
The following describes how to create a webhook.
You can create up to 10 webhooks in a repository.
- Access the NAVER Cloud Platform console.
- Click the Services > Developer Tools > SourceCommit menus.
- Select the relevant repository from the SourceCommit page, and click the [Go to code] button.
- You can also click the repository name from the repository list.
- From the repository's detailed functions page, click the [Hooks] tab.
- Click the [Create] button.
- Enter the name and description for the webhook you want to create.
- For webhook names, enter up to 50 characters including alphabets, numbers, and special characters (-, _). You can’t enter the same name as a webhook that has already been created.
- You can enter a description up to 300 characters.
- Select the type of event your webhook will be called on.
- If the event occurs in the repository to which the webhook belongs, the webhook is called.
- For more information about the event types, see the Webhook event list.
- Add a target to connect to the webhook. If called in case of an event, the webhook passes data through the connection target.
The methods to add targets can vary depending on the target type. See the following guides.
Adding Cloud Functions connection target
- To use Cloud Functions as a connection target type, you must use Cloud Functions , a paid service. For more information about Cloud Functions, see the Cloud Functions user guide.
- Cloud Functions triggers for SourceCommit are only available in the Korea region and in VPC.
- You can activate up to 10 triggers in a webhook.
- Select Cloud Functions for the target type.
- Click the [Create trigger] button to create a new trigger.
- For more details on trigger creation, see the SourceCommit Trigger user guide.
- If you’ve already created a SourceCommit trigger through the Cloud Functions service, you can skip this step.
- Select a trigger to connect to the webhook from the trigger list in the Creating webhook window.
- Select whether to activate the selected trigger.
- If an event occurs in the repository and the webhook is called, only the selected triggers whose activation status is ON are run.
- If an event occurs in the repository and the webhook is called, only the selected triggers whose activation status is ON are run.
- Click the [Create] button in the Creating webhook window to create a webhook.
Adding URL connection target
You can activate up to 10 URLs in a webhook.
- Select URL for the target type.
- Enter the URL , Content Type , and Secret to connect.
- URL: you can enter up to 2000 characters, and the addresses must allow external access (Required)
CautionIf the URL target returns HTTP status 3XX, redirection is not supported.
- Content Type: select between application/json , application/x-www-form-urlencode (Required)
Note- application/json : send JSON payload directly to request body data
- application/x-www-form-urlencoded : send JSON payload as the value for 'payload' key
- Secret (optional)
- To ensure that your webhook call is from the SourceCommit service and to prevent data forgery on the way
- When you call your webhook, the value of the request body encrypted with Hmac SHA256 into a secret key is sent via the 'x-ncp-sourcecommit-signature-v1’ (Example)
- Enter up to 200 characters
- Decide whether to activate the URL, and click the [Add] button to create it.
- If an event occurs in the repository and the webhook is called, the data is delivered only to the selected URLs whose activation status is ON.
- Click the [Create] button in the Creating webhook window to create a webhook.
Changing webhook settings
If necessary, you can change the descriptions, event type, and connection target information entered when creating the webhook.
The following describes how to change your webhook settings.
- Access the NAVER Cloud Platform console.
- Click the Services > Developer Tools > SourceCommit menus.
- Select the relevant repository from the SourceCommit page, and click the [Go to code] button.
- You can also click the repository name from the repository list.
- From the repository's detailed functions page, click the [Hooks] tab.
- Click the [Edit] button.
- Change the webhook settings, and click the [Apply] button.
- For more information about what to enter in the webhook settings, see Creating webhook.
Delete webhook
If you don’t want to call your webhook anymore, you can delete it. The following describes how to delete a webhook.
- Access the NAVER Cloud Platform console.
- Click the Services > Developer Tools > SourceCommit menus.
- Select the relevant repository from the SourceCommit page, and click the [Go to code] button.
- You can also click the repository name from the repository list.
- From the repository's detailed functions page, click the [Hooks] tab.
- From your webhook list, select a webhook to delete and click the [Delete] button.
- When the Confirm deletion window appears, click the [Delete] button.
Checking webhook call result
You can check the results of your webhook calls for each connection target.
- Checking call results for Cloud Functions connection target
- Checking call results for URL connection target
Checking call results for Cloud Functions connection target
If your webhook’s connection target is Cloud Functions , you can check the call result in the Cloud Functions service console.
- Access the NAVER Cloud Platform console.
- Click the Services > Developer Tools > SourceCommit menus.
- Select the relevant repository from the SourceCommit page, and click the [Go to code] button.
- You can also click the repository name from the repository list.
- From the repository's detailed functions page, click the [Hooks] tab.
- Click the trigger name in the [Target information] column of the webhook you want to check, and move to the Cloud Functions service console.
- For more information about trigger call results, see the Trigger monitoring guide.
Checking call results for URL connection target
If your webhook’s connection target is URL, you can click the [Call result] button from the webhook list page to check the results.
- Access the NAVER Cloud Platform console.
- Click the Services > Developer Tools > SourceCommit menus.
- Select the relevant repository from the SourceCommit page, and click the [Go to code] button.
- You can also click the repository name from the repository list.
- From the repository's detailed functions page, click the [Hooks] tab.
- Click the URL webhook to check the call result of, and click the [Call result] button.
- Target type: webhook target type (now only supports URL)
- Endpoint: webhook target URL
- Call time: webhook call time
- Status: call success/failure
- To check the detailed call result, click the [View] button.
- Request information
- Request header: URL, Method, and Headers information at webhook call
- Request body: body information delivered at webhook call
- Response information
- Response status code: HTTP Status Code received in response to webhook call
- Response header: Headers received in response to webhook call
- Response body: Body received in response to webhook call
- Request information
Receiving URL target webhook data
The following is an example of proving forgery and outputting the result using the secret value and the 'x-ncp-sourcecommit-signature-v1' header after receiving URL target webhook data.
By referring to Creating webhook and Adding URL connection target, create a webhook as follows:
Note- When you send your URL webhook data, the HTTP Method is POST.
- When you call your webhook, the value of the request body encrypted with Hmac SHA256 into a secret key is sent via the 'x-ncp-sourcecommit-signature-v1' header.
- If the Secret value is blank, the 'x-ncp-sourcecommit-signature-v1' header is not provided.
Be prepared to receive the webhook data from your web server.
CautionThe secret value needs to be stored carefully to prevent leakage. The following code is only for reference.
Spring boot
@RestController public class SampleController { @PostMapping("/test") public String test( @RequestHeader("x-ncp-sourcecommit-signature-v1") String signature, @RequestBody String data ) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, JsonProcessingException { String secret = "my-secret-key"; Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")); String expectedSignature = Base64.encodeBase64String(mac.doFinal(data.getBytes("UTF-8"))); if(!expectedSignature.equals(signature)){ System.out.println("this request failed validation"); } ObjectMapper mapper = new ObjectMapper(); Map<String, Object> map = mapper.readValue(data, new TypeReference<Map<String, Object>>() {}); System.out.println("--- received payload ---"); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map)); return "test"; } }
Node.js - express
router.post('/test', (req, res, next) => { const secret = 'my-secret-key'; const signature = req.get('x-ncp-sourcecommit-signature-v1'); const data = JSON.stringify(req.body); const expectedSignature = createHmac('sha256', secret).update(data).digest('base64'); if(expectedSignature !== signature){ console.log('this request failed validation'); } console.log('--- received payload ---'); console.log(JSON.stringify(req.body, null, 2)); res.send('test'); });
- Run one of the event types you’ve selected.
- The following is an example of a push event.
- The following is an example of a push event.
- Check the webhook receipt log in your web server console.