Sending PR id and other info with Bitbucket Cloud webhooks - bitbucket

I am looking at the docs for webhooks for Bitbucket Cloud:
https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html
I can send a GET request to the url in the url field, but I want to send the commit of the branch that changed, or the PR id, so that I can send a request back to Bitbucket to update Bitbucket's UI. Is there a way to include dynamic values in the url field in the webhooks form?

Bitbucket will send the info for you in the request body, not in query params, it looks like this:
{ push: { changes: [ [Object] ] },
actor:
{ username: 'ntrs_oleg',
display_name: 'Foo',
uuid: '{c0e09bb2-26e-f89afe7b1b2c}',
links: { self: [Object], html: [Object], avatar: [Object] },
nickname: 'interos_alex',
type: 'user',
account_id: '5cc0db15c66f0ffe44c597' },
repository:
{ scm: 'git',
website: '',
name: 'jenkins-jobs',
links: { self: [Object], html: [Object], avatar: [Object] },
project:
{ key: 'DEVOPS',
type: 'project',
uuid: '{2dc188bd997eaa244d9}',
links: [Object],
name: 'devops' },
full_name: 'interos/jenkins-jobs',
owner:
{ username: 'interos',
display_name: 'Interos',
type: 'team',
uuid: '{d4ee7ec3-04fce894572}',
links: [Object] },
type: 'repository',
is_private: true,
uuid: '{4c6795ff-362eb64d935b9}' } }

Related

How to pass authorization token with Swagger

I'm working on creating a custom connector in PowerApps which needs to call an API. The API needs an authorization token passed. Sending the request via Postman, this is set as follows:
Authorization: Bearer 2b3fdha04a4d89aad9c263d5d716bcc379aff0008
When I try to do the same thing via Swagger, the header gets sent like this:
Access-Control-Request-Headers: Authorization
This is how I'm trying to pass the token:
- {name: Authorization, in: header, description: This is the API key, required: true, type: string}
And this is my complete Swagger definition file:
`
swagger: '2.0'
info: {version: 1.0.0, title: ACME Corp, description: ACME sample API}
host: acmeapis.com
basePath: /
schemes: [https]
consumes: [multipart/form-data]
produces: [application/json]
securityDefinitions: {}
paths:
/v4_server/external/v1/authenticate:
post:
summary: Authorize
description: Used to get an authorization token
operationId: Authorize
parameters:
- {in: formData, name: api_key, type: string, description: The API key., required: true}
- {in: formData, name: client_db, type: string, description: The database to use.,
required: true}
- {in: formData, name: username, type: string, description: The username, required: true}
responses:
default:
description: All is well
schema:
type: object
properties:
access_token: {type: string, description: access_token}
expires_in: {type: integer, format: int32, description: expires_in}
refresh_token: {type: string, description: refresh_token}
/v4_server/external/v1/maintenance/resources/properties:
get:
summary: Building/Property Location
- Bearer: []
description: Building/Property Location
operationId: Building_propertyLocation
parameters:
- {name: property_use_id, default: '2', in: query, type: string, required: true}
- {name: $orderBy, default: unit, in: query, type: string, required: true}
- {name: Authorization, in: header, description: This is the API key, required: true, type: string}
responses:
'200': {description: Will send `Authenticated`}
'403': {description: 'You do not have necessary permissions for the resource,'}
default:
description: default
schema: {}
/: {}
definitions: {}
parameters: {}
responses: {}
security: []
tags: []
`
I can't find any examples on how to do this. Can someone point me the way.
Tks
Add the following lines under the schema
securityDefinitions:
Bearer:
type: apiKey
name: Authorization
in: header
description: >-
Enter the token with the `Bearer: ` prefix, e.g. "Bearer abcde12345".
Here is your full swagger (I've tested it on swagger editor - just copy and past into it to see the result)
swagger: '2.0'
info: {version: 1.0.0, title: ACME Corp, description: ACME sample API}
host: acmeapis.com
basePath: /
schemes: [https]
securityDefinitions:
Bearer:
type: apiKey
name: Authorization
in: header
description: >-
Enter the token with the `Bearer: ` prefix, e.g. "Bearer abcde12345".
consumes: [multipart/form-data]
produces: [application/json]
paths:
/v4_server/external/v1/authenticate:
post:
summary: Authorize
description: Used to get an authorization token
operationId: Authorize
parameters:
- {in: formData, name: api_key, type: string, description: The API key., required: true}
- {in: formData, name: client_db, type: string, description: The database to use.,
required: true}
- {in: formData, name: username, type: string, description: The username, required: true}
responses:
default:
description: All is well
schema:
type: object
properties:
access_token: {type: string, description: access_token}
expires_in: {type: integer, format: int32, description: expires_in}
refresh_token: {type: string, description: refresh_token}
/v4_server/external/v1/maintenance/resources/properties:
get:
summary: Building/Property Location
description: Building/Property Location
operationId: Building_propertyLocation
parameters:
- {name: property_use_id, default: '2', in: query, type: string, required: true}
- {name: $orderBy, default: unit, in: query, type: string, required: true}
- {name: Authorization, in: header, description: This is the API key, required: true, type: string}
responses:
'200': {description: Will send `Authenticated`}
'403': {description: 'You do not have necessary permissions for the resource,'}
default:
description: default
schema: {}
/: {}
definitions: {}
parameters: {}
responses: {}
security: []
tags: []

How to send github action artifact in a slack notification

I'm trying to send customized slack notifications about the status of github action workflows. I've built my custom messages with the help of https://github.com/8398a7/action-slack integration.
However, I'm trying to send the github action artifact that is generated with each workflow to my slack channel. Is that something that can be done?
Below is the yaml file that I'm using:
...
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
smoke-test:
runs-on: ubuntu-latest
container:
image: dannydainton/htmlextra
steps:
- name: Cloning Repository
id: initializing
uses: actions/checkout#master
- name: Executing API test suite
run: newman run "postman_collection.json" --environment "postman_environment.json" --reporters cli,htmlextra --reporter-htmlextra-export report.html
- if: failure()
uses: actions/upload-artifact#v2
id: generating-report
with:
name: reports
path: report.html
- uses: 8398a7/action-slack#v3
with:
status: custom
custom_payload: |
{
text: "Test Execution Passed",
attachments: [{
color: 'good',
text: `Test Execution for ${process.env.AS_WORKFLOW} workflow has SUCCEEDED! :heavy_check_mark:`,
fields: [{
title: "Test Type",
value: 'Smoke Test',
short: false
},
{
title: "Overall APIs Status",
value: "Healthy :heavy_check_mark:",
short: false
},
{
title: "Repository",
value: `${process.env.AS_REPO}`,
short: false
},
{
title: "Author",
value: `${process.env.AS_AUTHOR}`,
short: false
},
{
title: "Execution Time",
value: `${process.env.AS_TOOK}`,
short: false
},
{
title: "Number of Requests",
value: '39',
short: true
},
{
title: "Number of Assertions",
value: '64',
short: true
}]
}]
}
if: success()
- uses: 8398a7/action-slack#v3
if: failure()
with:
status: custom
custom_payload: |
{
text: 'Test Execution Failed :siren_alert::siren_alert:',
attachments: [{
color: 'danger',
text: `Test Execution for ${process.env.AS_WORKFLOW} workflow has FAILED! :x:`,
fields: [{
title: "Test Type",
value: 'Smoke Test',
short: true
},
{
title: "Repository",
value: `${process.env.AS_REPO}`,
short: true
},
{
title: "Author",
value: `${process.env.AS_AUTHOR}`,
short: false
}],
actions: [{
name: "report",
text: "View Report",
type: "button",
value: `https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}`
}]
}]
}
So I need to pass the artifact to the step which sends a slack notification on failure.
Thanks

iOS facebook login response does not contain profile data

I implemented Facebook login for both Android and iOS using react-native-facebook-login. I followed all of the instructions and it is working perfectly on Android. It works on iOS, but the response does not contain profile data.
Android Response:
declinedPermissions: [],
provider: 'facebook',
profile:{
id: '121212121212121212',
name: 'XYZ',
email: 'xyz#gmail.com',
first_name: 'XYZ',
last_name: 'XYZ',
age_range: { min: 21 },
link: 'https://www.facebook.com/app_scoped_user_id/121212121212121212/',
picture: { data: { is_silhouette: false,url: 'https://scontent.xx.fbcdn.net/v/t1.0-1/12/12.jpg?oh=12&oe=12' } },
gender: 'male',
locale: 'en_US',
timezone: 5.5,
updated_time: '2017-02-01T08:16:35+0000',verified: true },
type: 'success',
credentials: {
permissions: [ 'public_profile', 'contact_email', 'user_friends', 'email' ],
tokenExpirationDate: '2017-05-13T14:56:36.690+0530',
userId: '1212121212121212121',
token:'ababababababababbababababa' }
But on iOS, the response is incomplete and there is no profile data:
declinedPermissions: [],
credentials: { tokenExpirationDate: '2017-05-14T14:58:09+05:30',
permissions: [ 'email', 'contact_email', 'user_friends', 'public_profile' ],
userId:'12121212121212121',
token:'abababababababababababababa' },
missingPermissions: []
The code is same for both Android and iOS. And I did all of the configuration changes in Xcode. Is there something else that needs to be done to get the profile data on iOS?
We need to do another API call where we send the token which was generated into this API call.
fetch('https://graph.facebook.com/v2.5/me?fields=email,name,first_name,last_name,friends&access_token=' + YOUR_GENERATED_TOKEN)
.then((response) => response.json())
.then((json) => {
})
.catch(() => {
reject('ERROR')
})
This call will give you the profile details.

Is there a way to control loading relations in gorm with mongodb?

I'm building a REST api with grails 3 and mongo. I have encountered a problem when i need to marshal an object graph with a bigger depth.
I have the following domains:
class Category extends Resource {
/* other fields */
Category parent
}
class Product extends Resource {
/* other fields */
List<Category> categories
static hasMany = [categories: Category]
}
I have in the database the following structure(simplified for the sake of understanding):
categories:
{name: 'cat1'}
{name: 'cat2', parent: 'cat3'}
{name: 'cat3', parent: 'cat4'}
{name: 'cat4', parent: 'cat5'}
{name: 'cat5'}
product:
{categories: ['cat1', 'cat2']}
I am extending from RestfullController when creating my controllers. I want to be able to get a product and have the categories with parents in the returned json.
I get the following results:
/product/${id}
{
id: '...',
categories: [{
id: '...',
name: 'cat1'
}, {
id: '...',
name: 'cat2',
parent: { id: '...' }
}]
}
/category/cat2id
{
id: '...',
name: 'cat2',
parent: { id: '...' }
}
/category
[{
id: '...',
name: 'cat1'
},{
id: '...',
name: 'cat5'
},{
id: '...',
name: 'cat4',
parent: {
id: '...',
name: 'cat5'
}
},{
id: '...',
name: 'cat3',
parent: {
id: '...',
name: 'cat4',
parent: {
id: '...',
name: 'cat5'
}
}
},{
id: '...',
name: 'cat2',
parent: {
id: '...',
name: 'cat3',
parent: {
id: '...',
name: 'cat4',
parent: {
id: '...',
name: 'cat5'
}
}
}
}]
Why would Category.list() load the whole category object graph, and Category.get(), Product.get() and Product.list() would not load it? Is there a way to control this behaviour ?
The way Grails works is that it will only render associations that have already been loaded from the database, hence why you get some associations rendered and others not.
There is no built in way to control this behaviour other than writing your own marshaller. See http://grails.github.io/grails-doc/latest/guide/webServices.html#renderers

OAuth 2.0 Scope for Google Apps users' names with google-api-nodejs-client

I'm trying to use Google's 'google-api-nodejs-client' package (https://github.com/google/google-api-nodejs-client) to handle OAuth 2.0 authentication.
I've modified the example in examples/oauth2.js to console.log the entire profile object.
What scope can I use to correctly extract users' 'givenName' and 'familyName' if they're authenticating using a Google Apps account? Using the following scope:
scope: [
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.profile.emails.read'
]
returns the following response once authenticated:
{ kind: 'plus#person',
etag: '"LONG STRING"',
emails: [ { value: 'example#example.example', type: 'account' } ],
objectType: 'person',
id: '123456',
displayName: '',
name: { familyName: '', givenName: '' },
image:
{ url: 'https://lh3.googleusercontent.com/ etc etc',
isDefault: false },
isPlusUser: false,
language: 'en_GB',
circledByCount: 0,
verified: false,
domain: 'example.example' }
I tried fooling around with the API on the API Explorer (https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get?userId=me) and only needed the 'https://www.googleapis.com/auth/plus.login' scope to get my familyName and givenName.
Perhaps the user that you are requesting the data from does not have a given and family name set?

Resources