-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: This version creates a bot based on v11 of Hubot
- Loading branch information
1 parent
d4cecca
commit 4974174
Showing
30 changed files
with
7,719 additions
and
4,450 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Build and release pipeline | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- next | ||
pull_request: | ||
branches: | ||
- main | ||
- next | ||
permissions: | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
id-token: write | ||
jobs: | ||
build: | ||
name: Build and Verify | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 18.x | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies | ||
run: npm audit signatures | ||
test: | ||
name: Fast Tests | ||
runs-on: ubuntu-latest | ||
needs: build | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 18.x | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm test | ||
release: | ||
name: Release | ||
if: github.ref == 'refs/heads/main' && success() | ||
needs: [build, test, e2etest] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 18.x | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Semantic Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict' | ||
|
||
const yeoman = require('yeoman-generator') | ||
const chalk = require('chalk') | ||
const npmName = require('npm-name') | ||
import Generator from 'yeoman-generator' | ||
import chalk from 'chalk' | ||
|
||
function hubotStartSay () { | ||
return ' _____________________________ ' + '\n' + | ||
|
@@ -40,41 +38,11 @@ function hubotEndSay () { | |
'\n' | ||
} | ||
|
||
const HubotGenerator = yeoman.generators.Base.extend({ | ||
|
||
determineDefaultOwner: function () { | ||
let userName | ||
let userEmail | ||
|
||
if (typeof (this.user.git.name) === 'function') { | ||
userName = this.user.git.name() | ||
} else { | ||
userName = this.user.git.name | ||
} | ||
|
||
if (typeof (this.user.git.email) === 'function') { | ||
userEmail = this.user.git.email() | ||
} else { | ||
userEmail = this.user.git.email | ||
} | ||
|
||
if (userName && userEmail) { | ||
return userName + ' <' + userEmail + '>' | ||
} else { | ||
return 'User <[email protected]>' | ||
} | ||
}, | ||
|
||
determineDefaultName: function () { | ||
return this._.slugify(this.appname) | ||
}, | ||
|
||
defaultAdapter: 'campfire', | ||
defaultDescription: 'A simple helpful robot for your Company', | ||
|
||
constructor: function () { | ||
yeoman.generators.Base.apply(this, arguments) | ||
|
||
class HubotGenerator extends Generator { | ||
constructor () { | ||
super(...arguments) | ||
this.defaultAdapter = 'shell' | ||
this.defaultDescription = 'A simple helpful robot for your Company' | ||
// FIXME add documentation to these | ||
this.option('owner', { | ||
desc: 'Name and email of the owner of new bot (ie Example <[email protected]>)', | ||
|
@@ -123,140 +91,88 @@ const HubotGenerator = yeoman.generators.Base.extend({ | |
if (this.options.adapter === true) { | ||
this.env.error('Missing adapter name. Make sure to specify it like --adapter=<adapter>') | ||
} | ||
}, | ||
} | ||
|
||
async determineDefaultOwner () { | ||
const userName = await this.git.name() | ||
const userEmail = await this.git.email() | ||
|
||
if (userName && userEmail) { | ||
return userName + ' <' + userEmail + '>' | ||
} else { | ||
return 'User <[email protected]>' | ||
} | ||
} | ||
|
||
determineDefaultName () { | ||
return this.#slugify(this.appname) | ||
} | ||
|
||
initializing: function () { | ||
this.pkg = require('../../package.json') | ||
#slugify (text) { | ||
return text.toString().toLowerCase() | ||
.replace(/\s+/g, '-') // Replace spaces with - | ||
.replace(/[^\w-]+/g, '') // Remove all non-word chars | ||
.replace(/--+/g, '-') // Replace multiple - with single - | ||
.replace(/^-+/, '') // Trim - from start of text | ||
.replace(/-+$/, '') // Trim - from end of text | ||
} | ||
|
||
initializing () { | ||
this.externalScripts = [ | ||
'hubot-diagnostics', | ||
'hubot-help', | ||
'hubot-redis-brain', | ||
'hubot-rules' | ||
] | ||
}, | ||
|
||
prompting: { | ||
askFor: function () { | ||
const done = this.async() | ||
const botOwner = this.determineDefaultOwner() | ||
|
||
const prompts = [] | ||
if (!this.options.owner) { | ||
prompts.push({ | ||
name: 'botOwner', | ||
message: 'Owner', | ||
default: botOwner | ||
}) | ||
} | ||
|
||
this.log(hubotStartSay()) | ||
this.prompt(prompts, function (props) { | ||
this.botOwner = this.options.owner || props.botOwner | ||
|
||
done() | ||
}.bind(this)) | ||
}, | ||
|
||
askForBotNameAndDescription: function () { | ||
const done = this.async() | ||
const botName = this.determineDefaultName() | ||
|
||
const prompts = [] | ||
|
||
if (!this.options.name) { | ||
prompts.push({ | ||
name: 'botName', | ||
message: 'Bot name', | ||
default: botName | ||
}) | ||
} | ||
|
||
if (!this.options.description) { | ||
prompts.push({ | ||
name: 'botDescription', | ||
message: 'Description', | ||
default: this.defaultDescription | ||
}) | ||
} | ||
|
||
this.prompt(prompts, function (props) { | ||
this.botName = this.options.name || props.botName | ||
this.botDescription = this.options.description || props.botDescription | ||
|
||
done() | ||
}.bind(this)) | ||
}, | ||
|
||
askForBotAdapter: function () { | ||
const done = this.async() | ||
|
||
const prompts = [] | ||
// FIXME validate argument like we do when prompting | ||
if (!this.options.adapter) { | ||
prompts.push({ | ||
name: 'botAdapter', | ||
message: 'Bot adapter', | ||
default: this.defaultAdapter, | ||
validate: function (botAdapter) { | ||
const done = this.async() | ||
|
||
if (botAdapter === 'campfire') { | ||
done(null, true) | ||
return | ||
} | ||
|
||
const name = 'hubot-' + botAdapter | ||
npmName(name, function (error, unavailable) { | ||
if (error) throw error | ||
if (unavailable) { | ||
done("Can't find that adapter on NPM, try again?") | ||
return | ||
} | ||
} | ||
|
||
done(null, true) | ||
}) | ||
} | ||
}) | ||
async prompting () { | ||
const botOwner = await this.determineDefaultName() | ||
const prompts = [ | ||
{ | ||
type: 'input', | ||
name: 'botOwner', | ||
message: 'My Owner', | ||
default: botOwner | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'botName', | ||
message: 'Bot name', | ||
default: 'hubot' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'botDescription', | ||
message: 'Description', | ||
default: 'A simple helpful robot for your Company' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'botAdapter', | ||
message: 'Bot adapter', | ||
default: 'shell' | ||
} | ||
] | ||
this.props = await this.prompt(prompts) | ||
return this.props | ||
} | ||
|
||
this.prompt(prompts, function (props) { | ||
this.botAdapter = this.options.adapter || props.botAdapter | ||
|
||
done() | ||
}.bind(this)) | ||
} | ||
}, | ||
|
||
writing: { | ||
app: function () { | ||
this.mkdir('bin') | ||
this.copy('bin/hubot', 'bin/hubot') | ||
this.copy('bin/hubot.cmd', 'bin/hubot.cmd') | ||
|
||
this.template('Procfile', 'Procfile') | ||
this.template('README.md', 'README.md') | ||
|
||
this.write('external-scripts.json', JSON.stringify(this.externalScripts, undefined, 2)) | ||
|
||
this.copy('gitignore', '.gitignore') | ||
this.template('_package.json', 'package.json') | ||
|
||
this.directory('scripts', 'scripts') | ||
} | ||
}, | ||
|
||
end: function () { | ||
const packages = ['hubot'].concat(this.externalScripts).map(name => `${name}@latest`) | ||
|
||
if (this.botAdapter !== 'campfire') { | ||
packages.push('hubot-' + this.botAdapter) | ||
} | ||
|
||
this.npmInstall(packages, {'save': true}) | ||
writing () { | ||
this.log(hubotStartSay()) | ||
this.fs.copyTpl(this.templatePath('bin/hubot.cmd'), this.destinationPath('bin/hubot.cmd'), this.props) | ||
this.fs.copyTpl(this.templatePath('bin/hubot'), this.destinationPath('bin/hubot'), this.props) | ||
this.copyTemplate('scripts/', 'scripts/', null, this.props) | ||
this.fs.copyTpl(this.templatePath('Procfile'), this.destinationPath('Procfile'), this.props) | ||
this.fs.copyTpl(this.templatePath('README.md'), this.destinationPath('README.md'), this.props) | ||
this.writeDestinationJSON('external-scripts.json', this.externalScripts) | ||
this.copyTemplate('gitignore', '.gitignore', null, this.props) | ||
this.fs.copyTpl(this.templatePath('_package.json'), this.destinationPath('package.json'), this.props) | ||
} | ||
|
||
end () { | ||
this.log(hubotEndSay()) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = HubotGenerator | ||
export default HubotGenerator |
Oops, something went wrong.