1 | let _ = require('lodash')
|
2 | let cli = require('heroku-cli-util')
|
3 | let error = require('./error')
|
4 |
|
5 | let getOwner = function (owner) {
|
6 | if (isOrgApp(owner)) {
|
7 | return owner.split('@herokumanager.com')[0]
|
8 | }
|
9 | return owner
|
10 | }
|
11 |
|
12 | let isOrgApp = function (owner) {
|
13 | return (/@herokumanager\.com$/.test(owner))
|
14 | }
|
15 |
|
16 | let isValidEmail = function (email) {
|
17 | return /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)
|
18 | }
|
19 |
|
20 | let printGroups = function (group, type = {label: 'Organization'}) {
|
21 | group = _.sortBy(group, 'name')
|
22 | cli.table(group, {
|
23 | columns: [
|
24 | {key: 'name', label: type.label, format: o => cli.color.green(o)},
|
25 | {key: 'role', label: 'Role', format: r => r}
|
26 | ],
|
27 | printHeader: false
|
28 | })
|
29 | }
|
30 |
|
31 | let printGroupsJSON = function (group) {
|
32 | cli.log(JSON.stringify(group, null, 2))
|
33 | }
|
34 |
|
35 | let orgInfo = function * (context, heroku) {
|
36 | let teamOrOrgName = context.org || context.flags.team
|
37 | if (!teamOrOrgName) error.exit(1, 'No team or org specified.\nRun this command with --team or --org')
|
38 | return yield heroku.get(`/organizations/${context.org || context.flags.team}`)
|
39 | }
|
40 |
|
41 | let warnUsingOrgFlagInTeams = function (orgInfo, context) {
|
42 | if ((orgInfo.type === 'team') && (!context.flags.team)) {
|
43 | cli.warn(`${cli.color.cmd(context.org)} is a Heroku Team\nHeroku CLI now supports Heroku Teams.\nUse ${cli.color.cmd('-t')} or ${cli.color.cmd('--team')} for teams like ${cli.color.cmd(context.org)}`)
|
44 | }
|
45 | }
|
46 |
|
47 | module.exports = {
|
48 | getOwner,
|
49 | isOrgApp,
|
50 | isValidEmail,
|
51 | orgInfo,
|
52 | printGroups,
|
53 | printGroupsJSON,
|
54 | warnUsingOrgFlagInTeams
|
55 | }
|