Skip to content

Commit

Permalink
PROD-2739: Update the action to pass the actor value as meta attribute (
Browse files Browse the repository at this point in the history
#16)

* PROD-2739: Update the action to pass the login as  "user" meta attribute
  • Loading branch information
marcoguillenuio authored May 17, 2023
1 parent a9a4902 commit 5064aed
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 33 deletions.
21 changes: 19 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,10 @@ function checkBypass(reqUrl) {
if (!reqUrl.hostname) {
return false;
}
const reqHost = reqUrl.hostname;
if (isLoopbackAddress(reqHost)) {
return true;
}
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
if (!noProxy) {
return false;
Expand All @@ -2572,13 +2576,24 @@ function checkBypass(reqUrl) {
.split(',')
.map(x => x.trim().toUpperCase())
.filter(x => x)) {
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
if (upperNoProxyItem === '*' ||
upperReqHosts.some(x => x === upperNoProxyItem ||
x.endsWith(`.${upperNoProxyItem}`) ||
(upperNoProxyItem.startsWith('.') &&
x.endsWith(`${upperNoProxyItem}`)))) {
return true;
}
}
return false;
}
exports.checkBypass = checkBypass;
function isLoopbackAddress(host) {
const hostLower = host.toLowerCase();
return (hostLower === 'localhost' ||
hostLower.startsWith('127.') ||
hostLower.startsWith('[::1]') ||
hostLower.startsWith('[0:0:0:0:0:0:0:1]'));
}
//# sourceMappingURL=proxy.js.map

/***/ }),
Expand Down Expand Up @@ -18218,6 +18233,7 @@ const getSha = (eventName, payload) => {
const run = async (context) => {
const eventName = context != null ? context.eventName : github.context.eventName
const payload = context != null ? context.payload : github.context.payload
const login = payload.sender ? payload.sender.login : ''
const token = core.getInput('token')
const teamId = core.getInput('team_id')
core.setSecret(token)
Expand All @@ -18230,7 +18246,8 @@ const run = async (context) => {
image: core.getInput('image') || null,
branch: core.getInput('branch') || getBranch(eventName, payload),
commit: core.getInput('commit') || getSha(eventName, payload),
repo: core.getInput('repo') || payload.repository.full_name
repo: core.getInput('repo') || payload.repository.full_name,
meta: { user: login }
}
return got.post('https://events.cto.ai/', {
headers: {
Expand Down
4 changes: 3 additions & 1 deletion src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const getSha = (eventName, payload) => {
const run = async (context) => {
const eventName = context != null ? context.eventName : github.context.eventName
const payload = context != null ? context.payload : github.context.payload
const login = payload.sender ? payload.sender.login : ''
const token = core.getInput('token')
const teamId = core.getInput('team_id')
core.setSecret(token)
Expand All @@ -70,7 +71,8 @@ const run = async (context) => {
image: core.getInput('image') || null,
branch: core.getInput('branch') || getBranch(eventName, payload),
commit: core.getInput('commit') || getSha(eventName, payload),
repo: core.getInput('repo') || payload.repository.full_name
repo: core.getInput('repo') || payload.repository.full_name,
meta: { user: login }
}
return got.post('https://events.cto.ai/', {
headers: {
Expand Down
77 changes: 47 additions & 30 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const { NOCK_ENABLED, OPS_PLATFORM_TEST_TOKEN } = process.env

const TOKEN = OPS_PLATFORM_TEST_TOKEN || 'jifeo2903u089jf3920'
const TEAM_ID = 'i992-j9f23j09-j092j0'
const USER = { user: 'Codertocat' }
const ENDPOINT = 'https://events.cto.ai'

const setInput = (name, value) => {
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = value
Expand All @@ -40,7 +42,7 @@ test('Push event with only required fields has additional data added', async ({
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -50,7 +52,8 @@ test('Push event with only required fields has additional data added', async ({
image: null,
branch: 'simple-tag',
commit: '6113728f27ae82c7b1a177c8d03f9e96e0adf246',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -81,7 +84,7 @@ test('Push event with all parameters passed, uses the overwriting values', async
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -91,7 +94,8 @@ test('Push event with all parameters passed, uses the overwriting values', async
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -122,7 +126,7 @@ test('Pull Request event with only required fields has additional data added', a
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -132,7 +136,8 @@ test('Pull Request event with only required fields has additional data added', a
image: null,
branch: 'master',
commit: 'ec26c3e57ca3a959ca5aad62de7213c562f8c821',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -163,7 +168,7 @@ test('Pull Request event with all parameters passed, uses the overwriting values
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -173,7 +178,8 @@ test('Pull Request event with all parameters passed, uses the overwriting values
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -204,7 +210,7 @@ test('Deployment event with only required fields has additional data added', asy
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -214,7 +220,8 @@ test('Deployment event with only required fields has additional data added', asy
image: null,
branch: 'master',
commit: 'f95f852bd8fca8fcc58a9a2d6c842781e32a215e',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -245,7 +252,7 @@ test('Deployment event with all parameters passed, uses the overwriting values',
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -255,7 +262,8 @@ test('Deployment event with all parameters passed, uses the overwriting values',
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -286,7 +294,7 @@ test('Deployment Status event with only required fields has additional data adde
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -296,7 +304,8 @@ test('Deployment Status event with only required fields has additional data adde
image: null,
branch: 'master',
commit: 'f95f852bd8fca8fcc58a9a2d6c842781e32a215e',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -327,7 +336,7 @@ test('Deployment Status event with all parameters passed, uses the overwriting v
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -337,7 +346,8 @@ test('Deployment Status event with all parameters passed, uses the overwriting v
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -368,7 +378,7 @@ test('Status event with only required fields has additional data added', async (
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -378,7 +388,8 @@ test('Status event with only required fields has additional data added', async (
image: null,
branch: 'master',
commit: '6113728f27ae82c7b1a177c8d03f9e96e0adf246',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -409,7 +420,7 @@ test('Status event with all parameters passed, uses the overwriting values', asy
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -419,7 +430,8 @@ test('Status event with all parameters passed, uses the overwriting values', asy
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -450,7 +462,7 @@ test('Package event with only required fields has additional data added', async
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -460,7 +472,8 @@ test('Package event with only required fields has additional data added', async
image: null,
branch: 'master',
commit: null,
repo: 'Codertocat/hello-world-npm'
repo: 'Codertocat/hello-world-npm',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -491,7 +504,7 @@ test('Package event with all parameters passed, uses the overwriting values', as
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -501,7 +514,8 @@ test('Package event with all parameters passed, uses the overwriting values', as
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/hello-world-npm'
repo: 'Codertocat/hello-world-npm',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -532,7 +546,7 @@ test('Release event with only required fields has additional data added', async
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -542,7 +556,8 @@ test('Release event with only required fields has additional data added', async
image: null,
branch: 'master',
commit: null,
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -573,7 +588,7 @@ test('Release event with all parameters passed, uses the overwriting values', as
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -583,7 +598,8 @@ test('Release event with all parameters passed, uses the overwriting values', as
image: 'image-1',
branch: 'branch-1',
commit: '88888',
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down Expand Up @@ -614,7 +630,7 @@ test('Event without ref or sha only gets the fields passed and repo', async ({ i
}

if (NOCK_ENABLED) {
nock('https://events.cto.ai')
nock(ENDPOINT)
.matchHeader('authorization', `Bearer ${TOKEN}`)
.post('/', {
team_id: TEAM_ID,
Expand All @@ -624,7 +640,8 @@ test('Event without ref or sha only gets the fields passed and repo', async ({ i
image: null,
branch: null,
commit: null,
repo: 'Codertocat/Hello-World'
repo: 'Codertocat/Hello-World',
meta: USER
})
.reply(200, { message: 'event written', data: {} })
}
Expand Down

0 comments on commit 5064aed

Please sign in to comment.