Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Update teamId to workspaceId
Browse files Browse the repository at this point in the history
  • Loading branch information
David Dooling committed Aug 3, 2018
1 parent 20659a3 commit fcc185f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
37 changes: 30 additions & 7 deletions lib/commands/editor/node/updateAtomistTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,37 @@
* limitations under the License.
*/

import { HandlerContext } from "@atomist/automation-client";
import { Project } from "@atomist/automation-client/project/Project";
import {
HandlerContext,
logger,
} from "@atomist/automation-client";
import {
File,
} from "@atomist/automation-client/project/File";
import {
Project,
} from "@atomist/automation-client/project/Project";
import * as path from "path";

export async function updateAtomistTeam(project: Project, ctx: HandlerContext) {
const atomistConfigFile = await project.findFile("src/atomist.config.ts");
const content = await atomistConfigFile.getContent();
const newContent = content.replace(/teamIds:\s*\[[^\]]*]/,
`teamIds: ["${ctx.teamId}"]`);
await atomistConfigFile.setContent(newContent);
try {
let atomistConfigFile: File;
for (const dir of ["src", "lib"]) {
atomistConfigFile = await project.getFile(path.join(dir, "atomist.config.ts"));
if (atomistConfigFile) {
break;
}
}
if (!atomistConfigFile) {
return project;
}
const content = await atomistConfigFile.getContent();
const newContent = content
.replace(/\bworkspaceIds\s*:\s*\[[^\]]*]/, `workspaceIds: ["${ctx.workspaceId}"]`)
.replace(/\bteamIds\s*:\s*\[[^\]]*]/, `workspaceIds: ["${ctx.workspaceId}"]`);
await atomistConfigFile.setContent(newContent);
} catch (e) {
logger.warn(`Failed to update Atomist workspace: ${e.message}`);
}
return project;
}
11 changes: 5 additions & 6 deletions test/commands/editor/node/updateAtomistTeam.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { updateAtomistTeam } from "../../../../lib/commands/editor/node/updateAt
describe("update Atomist Team", () => {

const fakeContext = {
teamId: "TEAMYAY",
workspaceId: "TEAMYAY",
} as any as HandlerContext;

it("changes the team", done => {
Expand All @@ -35,7 +35,7 @@ describe("update Atomist Team", () => {
export const configuration: Configuration = {
name: pj.name,
version: pj.version,
teamIds: ["T5964N9B7"], // <-- run @atomist pwd in your slack team to obtain the team id
workspaceIds: ["T5964N9B7"], // <-- run @atomist pwd in your slack team to obtain the team id
commands: assembled.commandHandlers.concat([
HelloWorld,
() => affirmationEditor,
Expand All @@ -47,13 +47,12 @@ export const configuration: Configuration = {
};
`,
});
const ec = `teamIds: ["TEAMYAY"], // <-- run @atomist pwd in your slack team to obtain the team id`;
updateAtomistTeam(p, fakeContext)
.then(
edited => edited.findFile("src/atomist.config.ts"))
.then(f => f.getContent())
.then(content => {
assert(content.includes(ec),
assert(content.includes(`workspaceIds: ["TEAMYAY"], // <-- run @atomist pwd in your slack team to obt`),
"content: " + content);
})
.then(done, done);
Expand All @@ -67,7 +66,7 @@ export const configuration: Configuration = {
export const configuration: Configuration = {
name: pj.name,
version: pj.version,
teamIds: [
workspaceIds: [
// "T1JVCMVH7",
"T5964N9B7", // spring-team
// "T29E48P34", // Atomist community
Expand All @@ -88,7 +87,7 @@ export const configuration: Configuration = {
edited => edited.findFile("src/atomist.config.ts"))
.then(f => f.getContent())
.then(content => {
assert(content.includes(`teamIds: ["TEAMYAY"],\n commands:`),
assert(content.includes(`workspaceIds: ["TEAMYAY"],\n commands:`),
"content: " + content);
})
.then(done, done);
Expand Down

0 comments on commit fcc185f

Please sign in to comment.