Skip to content

Commit

Permalink
refactor: webhooks2tasks to support trigger user and source
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Dec 27, 2023
1 parent ab1c191 commit 0ad8722
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export async function bitbucketPullRequestUpdated(webhook: WebhookRequestData, p
}

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.pullrequest.author.username) {
triggerUser = body.pullrequest.author.username
}
const data: deployData = {
repoName: body.repository.full_name,
repoUrl: body.repository.links.html.href,
Expand All @@ -61,7 +66,9 @@ export async function bitbucketPullRequestUpdated(webhook: WebhookRequestData, p
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.pullrequest.id}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/bitbucketPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ export async function bitbucketPush(webhook: WebhookRequestData, project: Projec

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.actor.username) {
triggerUser = body.actor.username
}
const data: deployData = {
projectName: project.name,
type: 'branch',
branchName: branchName,
sha: sha,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

let logMessage = `\`<${body.push.changes[0].new.links.html.href}>\``
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/giteaPullRequestOpened.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export async function giteaPullRequestOpened(webhook: WebhookRequestData, projec

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.sender.login) {
triggerUser = body.sender.login
}
const data: deployData = {
repoUrl: body.repository.html_url,
repoName: body.repository.full_name,
Expand All @@ -61,7 +67,9 @@ export async function giteaPullRequestOpened(webhook: WebhookRequestData, projec
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.number}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export async function giteaPullRequestSynchronize(webhook: WebhookRequestData, p

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.sender.login) {
triggerUser = body.sender.login
}
const data: deployData = {
repoName: body.repository.full_name,
repoUrl: body.repository.html_url,
Expand All @@ -79,7 +85,9 @@ export async function giteaPullRequestSynchronize(webhook: WebhookRequestData, p
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.number}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/giteaPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ export async function giteaPush(webhook: WebhookRequestData, project: Project) {

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.sender.login) {
triggerUser = body.sender.login
}
const data: deployData = {
projectName: project.name,
type: 'branch',
branchName: branchName,
sha: sha,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

let logMessage = `\`<${body.repository.html_url}/tree/${meta.branch}|${meta.branch}>\``
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/githubPullRequestOpened.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export async function githubPullRequestOpened(webhook: WebhookRequestData, proje

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.sender.login) {
triggerUser = body.sender.login
}
const data: deployData = {
repoUrl: body.repository.html_url,
repoName: body.repository.full_name,
Expand All @@ -61,7 +67,9 @@ export async function githubPullRequestOpened(webhook: WebhookRequestData, proje
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.number}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export async function githubPullRequestSynchronize(webhook: WebhookRequestData,

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.sender.login) {
triggerUser = body.sender.login
}
const data: deployData = {
repoName: body.repository.full_name,
repoUrl: body.repository.html_url,
Expand All @@ -79,7 +85,9 @@ export async function githubPullRequestSynchronize(webhook: WebhookRequestData,
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.number}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/githubPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ export async function githubPush(webhook: WebhookRequestData, project: Project)

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.sender.login) {
triggerUser = body.sender.login
}
const data: deployData = {
projectName: project.name,
type: 'branch',
branchName: branchName,
sha: sha,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

let logMessage = `\`<${body.repository.html_url}/tree/${meta.branch}|${meta.branch}>\``
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/gitlabPullRequestOpened.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.user.username) {
triggerUser = body.user.username
}
const data: deployData = {
repoUrl: body.object_attributes.target.web_url,
repoName: body.object_attributes.target.name,
Expand All @@ -61,7 +67,9 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.object_attributes.iid}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.user.username) {
triggerUser = body.user.username
}
const data: deployData = {
repoUrl: body.object_attributes.target.web_url,
repoName: body.object_attributes.target.name,
Expand All @@ -61,7 +67,9 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.object_attributes.iid}`,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

try {
Expand Down
10 changes: 9 additions & 1 deletion services/webhooks2tasks/src/handlers/gitlabPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ export async function gitlabPush(webhook: WebhookRequestData, project: Project)

let buildName = generateBuildId();

// try get the user from the webhook payload
// otherwise just use "webhook" as the trigger user
let triggerUser = "webhook"
if (body.user_username) {
triggerUser = body.user_username
}
const data: deployData = {
projectName: project.name,
type: 'branch',
branchName: branchName,
sha: sha,
buildName: buildName
buildName: buildName,
triggerUser: triggerUser,
triggerSource: "WEBHOOK",
}

let logMessage = `\`<${body.project.http_url}/tree/${meta.branch}|${meta.branch}>\``
Expand Down
2 changes: 2 additions & 0 deletions services/webhooks2tasks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface deployData {
buildPriority?: string,
bulkId?: string,
buildVariables?: any,
triggerUser?: string,
triggerSource?: string,
};

export interface WebhookRequestData {
Expand Down

0 comments on commit 0ad8722

Please sign in to comment.