Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle more cases where automations make changes #57

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
required: false
default: '15'
dependabot-fallback:
description: 'The fallback GitHub username to use for standard changes when created by a Dependabot auto-merge.'
description: 'The Net ID to assign changes to when robots make changes (e.g., on a Dependabot auto-merge).'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we always needed Net IDs, not GitHub usernames, so this isn't actually a change.

required: false
outputs:
change-sys-id:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

41 changes: 29 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,7 @@ Last updated on: ${alreadyCreatedRfc.sys_updated_on}`)
process.exit(0)
}

const netId = await getNetIdAssociatedWithGithubUsernameInServicenow(githubUsername).catch(() => {
const isDependabot = (payload.pusher.name === 'dependabot[bot]' || payload.pusher.name === 'dependabot-merge-action[bot]')
if (isDependabot) {
const dependabotFallback = getInput('dependabot-fallback')
if (dependabotFallback !== '') {
return dependabotFallback
} else {
warning(`Could not get dependabot-fallback input. This action will fail.
If you want Dependabot auto-merges to succeed, use that input to define a GitHub username to attach Dependabot changes to.\n`)
}
}

const netId = await determineNetIdToAttributeRfc(githubUsername, templateId).catch(() => {
error(`⚠ An error occurred while getting the Net ID associated with your GitHub username.
Is your GitHub username associated with your profile in ServiceNow?
You can check by going to https://${servicenowHost}/nav_to.do?uri=%2Fsys_user.do%3Fsys_id%3Djavascript:gs.getUserID()%26sysparm_view%3Dess`)
Expand Down Expand Up @@ -158,6 +147,34 @@ async function getRfcIfAlreadyCreated (linkToWorkflowRun) {
return existingRfc
}

async function determineNetIdToAttributeRfc (githubUsername, templateId) {
// If this is some automated change (e.g. on a schedule or from Dependabot)
const isAutomation = (githubUsername === 'byu-oit-bot' || githubUsername === 'github-actions[bot]')
const isDependabot = (githubUsername === 'dependabot[bot]' || githubUsername === 'dependabot-merge-action[bot]')
if (isAutomation || isDependabot) {
// If dependabot-fallback input is provided, attribute the change to that Net ID
const dependabotFallback = getInput('dependabot-fallback')
if (dependabotFallback !== '') {
return dependabotFallback
}

// Otherwise, if an application-specific standard change template was specified (i.e., not the generic one baked into our template repos),
// attribute the change to our GitHub Actions bot user in ServiceNow. A useful template is required so that Ops still knows who to contact
// if something goes wrong with the change.
const genericTemplateInUse = (templateId === 'Codepipeline-Standard-Change')
if (!genericTemplateInUse) {
return 'githubac'
}

warning(`This change appears to have been made by a robot. Ops needs to know who to contact if something goes wrong.
You have two options to fix this:
1) Use a more specific standard change template.
2) Blame a human for this change by providing a Net ID in the dependabot-fallback input.\n`)
}

return getNetIdAssociatedWithGithubUsernameInServicenow(githubUsername)
}

async function getNetIdAssociatedWithGithubUsernameInServicenow (githubUsername) {
const optionsToGetNetId = {
method: 'GET',
Expand Down
Loading