mirror of
https://github.com/status-im/status-github-bot.git
synced 2025-02-27 20:30:37 +00:00
Add templating support to welcome bot
This commit is contained in:
parent
4f1a3be931
commit
4513976cb9
@ -96,7 +96,12 @@ The bot gets its settings from a per-repo file located at `.github/github-bot.ym
|
||||
Examples of settings that can be configured:
|
||||
|
||||
- `github-team/slug`: Slug of the team that owns the respective repository
|
||||
- `welcome-bot/message`: First time contributor welcome message
|
||||
- `welcome-bot/message-template`: First time contributor welcome message template. Examples of template values allowed:
|
||||
|
||||
- `{user}`: Replaced by the PR submitter's user name
|
||||
- `{repo-name}`: Replaced by the PR's target repository name
|
||||
- `{pr-number}`: Replaced by the PR number
|
||||
|
||||
- `slack/notification/room`: Slack room used for notifications (e.g. `status-probot`)
|
||||
|
||||
- Repository project board settings:
|
||||
|
@ -26,6 +26,20 @@ module.exports = (robot) => {
|
||||
})
|
||||
}
|
||||
|
||||
function executeTemplate (templateString, templateVars) {
|
||||
let s = templateString
|
||||
|
||||
for (const templateVar in templateVars) {
|
||||
if (templateVars.hasOwnProperty(templateVar)) {
|
||||
const value = templateVars[templateVar]
|
||||
|
||||
s = s.replace(`{${templateVar}}`, value)
|
||||
}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
async function greetNewContributor (context, robot) {
|
||||
const { github, payload } = context
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
@ -51,7 +65,8 @@ async function greetNewContributor (context, robot) {
|
||||
const userPullRequests = ghissuesPayload.data.filter(issue => issue.pull_request)
|
||||
if (userPullRequests.length === 1) {
|
||||
try {
|
||||
const welcomeMessage = welcomeBotConfig.message
|
||||
const welcomeMessage = executeTemplate(welcomeBotConfig['message-template'], { user: payload.pull_request.user.login, 'pr-number': prNumber, 'repo-name': repoName })
|
||||
|
||||
if (process.env.DRY_RUN) {
|
||||
robot.log(`${botName} - Would have created comment in GHI`, ownerName, repoName, prNumber, welcomeMessage)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user