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

refactor: migrate members:set to oclif/core #2674

Merged
merged 3 commits into from
Mar 4, 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
21 changes: 21 additions & 0 deletions packages/cli/src/commands/members/set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Command, flags} from '@heroku-cli/command'
import {RoleCompletion} from '@heroku-cli/command/lib/completions'
import {addMemberToTeam} from '../../lib/members/utils'

export default class MembersSet extends Command {
static topic = 'members'
static description = 'sets a members role in a team'
static strict = false
static flags = {
role: flags.string({char: 'r', required: true, description: 'member role (admin, collaborator, member, owner)', completion: RoleCompletion}),
team: flags.team({required: true}),
}

public async run(): Promise<void> {
const {flags, argv} = await this.parse(MembersSet)
const {role, team} = flags
const email = argv[0] as string

await addMemberToTeam(email, role, team, this.heroku, 'PATCH')
}
}
15 changes: 15 additions & 0 deletions packages/cli/src/lib/members/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Heroku from '@heroku-cli/schema'
import {ux} from '@oclif/core'
import color from '@heroku-cli/color'
import {APIClient} from '@heroku-cli/command'

export const addMemberToTeam = async function (email: string, role: string, groupName: string, heroku: APIClient, method = 'PUT') {
ux.action.start(`Adding ${color.cyan(email)} to ${color.magenta(groupName)} as ${color.green(role)}`)
await heroku.request<Heroku.TeamMember[]>(
`/teams/${groupName}/members`,
{
method: method,
body: {email, role},
})
ux.action.stop()
}
75 changes: 75 additions & 0 deletions packages/cli/test/unit/commands/members/set.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {stdout, stderr} from 'stdout-stderr'
import {expect} from 'chai'
import * as nock from 'nock'
import Cmd from '../../../../src/commands/members/set'
import runCommand from '../../../helpers/runCommand'
import {
teamFeatures,
teamInfo,
variableSizeTeamInvites,
variableSizeTeamMembers,
} from '../../../helpers/stubs/get'
import {updateMemberRole} from '../../../helpers/stubs/patch'

describe('heroku members:set', () => {
let apiUpdateMemberRole: nock.Scope
beforeEach(() => {
teamFeatures([])
})
afterEach(() => nock.cleanAll())

context('and group is a team', () => {
beforeEach(() => {
teamInfo('team')
})
it('does not warn the user when under the free org limit', () => {
variableSizeTeamMembers(1)
variableSizeTeamInvites(0)
apiUpdateMemberRole = updateMemberRole('[email protected]', 'admin')
return runCommand(Cmd, [
'--role',
'admin',
'--team',
'myteam',
'[email protected]',
])
.then(() => expect('').to.eq(stdout.output))
.then(() => expect('Adding [email protected] to myteam as admin...\nAdding [email protected] to myteam as admin... done\n').to.eq(stderr.output))
.then(() => apiUpdateMemberRole.done())
})
it('does not warn the user when over the free org limit', () => {
variableSizeTeamMembers(7)
variableSizeTeamInvites(0)
apiUpdateMemberRole = updateMemberRole('[email protected]', 'admin')
return runCommand(Cmd, [
'--role',
'admin',
'--team',
'myteam',
'[email protected]',
])
.then(() => expect('').to.eq(stdout.output))
.then(() => expect('Adding [email protected] to myteam as admin...\nAdding [email protected] to myteam as admin... done\n').to.eq(stderr.output))
.then(() => apiUpdateMemberRole.done())
})
})
context('and group is an enterprise org', () => {
beforeEach(() => {
teamInfo('enterprise')
variableSizeTeamMembers(1)
})
it('adds a member to an org', () => {
apiUpdateMemberRole = updateMemberRole('[email protected]', 'admin')
return runCommand(Cmd, [
'--team',
'myteam',
'--role',
'admin',
'[email protected]',
])
.then(() => expect('').to.eq(stdout.output))
.then(() => expect('Adding [email protected] to myteam as admin...\nAdding [email protected] to myteam as admin... done\n').to.eq(stderr.output))
.then(() => apiUpdateMemberRole.done())
})
})
})
30 changes: 0 additions & 30 deletions packages/orgs-v5/commands/members/set.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/orgs-v5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exports.commands = flatten([
require('./commands/apps/transfer'),
require('./commands/apps/unlock'),
require('./commands/members/add'),
require('./commands/members/set'),
require('./commands/members/remove'),
require('./commands/orgs'),
require('./commands/orgs/default'),
Expand Down
68 changes: 0 additions & 68 deletions packages/orgs-v5/test/unit/commands/members/set.unit.test.js

This file was deleted.

Loading