Skip to content

Commit 7285aec

Browse files
authored
feat(actors): propagates title/description (#992)
Propagates title and description from actor.json to the Apify Console. Updates the Actor's title and description when pushing if they differ from the current values. Adds tests to ensure that the title and description are correctly set when creating a new actor and updated on an existing actor. Fixes #723
1 parent a94969a commit 7285aec

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/commands/actors/push.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
185185
DEFAULT_RUN_OPTIONS) as ActorDefaultRunOptions;
186186
const newActor: ActorCollectionCreateOptions = {
187187
name: actorConfig!.name as string,
188+
title: actorConfig!.title as string | undefined,
189+
description: actorConfig!.description as string | undefined,
188190
defaultRunOptions,
189191
versions: [
190192
{
@@ -203,10 +205,11 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
203205
}
204206
}
205207

208+
const actorClient = apifyClient.actor(actorId);
209+
206210
info({ message: `Deploying Actor '${actorConfig!.name}' to Apify.` });
207211

208212
const filesSize = await sumFilesSizeInBytes(filePathsToPush, cwd);
209-
const actorClient = apifyClient.actor(actorId);
210213

211214
let sourceType;
212215
let sourceFiles;

test/api/commands/push.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,70 @@ describe('[api] apify push', () => {
308308
await testActorClient.version(actorJson.version).update({ buildTag: 'beta' });
309309

310310
await testRunCommand(ActorsPushCommand, { args_actorId: testActor.id, flags_noPrompt: true });
311+
if (testActor) await testActorClient.delete();
311312

312313
expect(lastErrorMessage()).to.includes('is already on the platform');
313314
},
314315
TEST_TIMEOUT,
315316
);
316317

318+
it(
319+
'should set title and description when creating a new actor',
320+
async () => {
321+
const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8'));
322+
323+
actorJson.name = `${actorJson.name}-title-test`;
324+
actorJson.title = 'My Custom Actor Title';
325+
actorJson.description = 'This is a custom description for the actor.';
326+
327+
writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' });
328+
await testRunCommand(ActorsPushCommand, { flags_noPrompt: true, flags_force: true });
329+
330+
const userInfo = await getLocalUserInfo();
331+
const actorId = `${userInfo.username}/${actorJson.name}`;
332+
actorsForCleanup.add(actorId);
333+
const createdActorClient = testUserClient.actor(actorId);
334+
const createdActor = await createdActorClient.get();
335+
336+
expect(createdActor?.title).to.be.eql('My Custom Actor Title');
337+
expect(createdActor?.description).to.be.eql('This is a custom description for the actor.');
338+
339+
if (createdActor) await createdActorClient.delete();
340+
},
341+
TEST_TIMEOUT,
342+
);
343+
344+
it(
345+
'should not rewrite current Actor title and description',
346+
async () => {
347+
const testActorWithTitleDesc = {
348+
...TEST_ACTOR,
349+
title: 'Original Title',
350+
description: 'Original description.',
351+
};
352+
let testActor = await testUserClient.actors().create(testActorWithTitleDesc);
353+
actorsForCleanup.add(testActor.id);
354+
const testActorClient = testUserClient.actor(testActor.id);
355+
356+
// Remove title and description from local actor.json
357+
const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8'));
358+
delete actorJson.title;
359+
delete actorJson.description;
360+
writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' });
361+
362+
await testRunCommand(ActorsPushCommand, { args_actorId: testActor.id, flags_noPrompt: true });
363+
364+
testActor = (await testActorClient.get())!;
365+
366+
if (testActor) await testActorClient.delete();
367+
368+
// Title and description should be preserved from the original actor
369+
expect(testActor.title).to.be.eql('Original Title');
370+
expect(testActor.description).to.be.eql('Original description.');
371+
},
372+
TEST_TIMEOUT,
373+
);
374+
317375
it(
318376
'should not push Actor when there are no files to push',
319377
async () => {

0 commit comments

Comments
 (0)