-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP code to implement update-deploy-status on PR
- Loading branch information
Showing
2 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const parseCheckboxStatus = (markdown) => { | ||
const lines = markdown.split("\n"); | ||
const checkboxStatuses = []; | ||
|
||
for (let line of lines) { | ||
// Match lines with checkboxes | ||
const match = line.match(/^\* \[([ x])\] Trigger (.+) deploy/); | ||
if (match) { | ||
const isChecked = match[1] === "x"; // Check if the checkbox is marked as checked | ||
const environment = match[2]; | ||
checkboxStatuses.push({ environment, isChecked }); | ||
} | ||
} | ||
return checkboxStatuses; | ||
}; | ||
|
||
module.exports = async ({ github, context, core, newStatus = {} }) => { | ||
const autogenPlaceholder = | ||
"<!-- AUTOGENERATED: DO NOT EDIT THIS LINE AND BELOW -->"; | ||
const currentPrBody = github.context.payload.pull_request?.body || ""; | ||
|
||
const p = currentPrBody.split(autogenPlaceholder); | ||
const existingText = parts[0]; | ||
const existingStatusMarkdown = parts[1]; | ||
let existingStatus; | ||
|
||
if (existingStatusMarkdown) { | ||
existingStatus = parseCheckboxStatus(existingStatus); | ||
} | ||
|
||
const actionLines = ["production", "staging", "testing"] | ||
.map((environment) => { | ||
let checkbox = " "; | ||
let suffix = ""; | ||
if (newStatus[environment] == true) { | ||
checkbox = "x"; | ||
suffix = "✅"; | ||
} | ||
return "* [${checkbox}] Trigger ${environment} deploy ${suffix}"; | ||
}) | ||
.join("\n"); | ||
|
||
const newBody = `${existingText} | ||
${autogenPlaceholder} | ||
## Deployment Actions 🚀 | ||
${actionLines} | ||
`; | ||
|
||
const prNumber = context.payload.pull_request.number; | ||
if (prNumber) { | ||
await github.rest.pulls.update({ | ||
owner, | ||
repo, | ||
pull_number: prNumber, | ||
body: newBody, | ||
}); | ||
} | ||
|
||
return existingStatus; | ||
}; |