-
Notifications
You must be signed in to change notification settings - Fork 57
feat: add task publish and unpublish commands #1317
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
Open
Janjiran
wants to merge
6
commits into
master
Choose a base branch
from
feat/task-publication
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5679f70
feat: add task publish and unpublish commands
Janjiran cbd7a5a
feat: review feedback changes [internal]
Janjiran b93c7d4
chore: update imports - review feedback [internal]
Janjiran 0707ee4
Merge branch 'master' into feat/task-publication
Janjiran 4984aa7
chore: update copy
Janjiran 98152a9
chore: bump apify-client
Janjiran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
|
Janjiran marked this conversation as resolved.
|
This file contains hidden or 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,71 @@ | ||
| import type { ApifyApiError } from 'apify-client'; | ||
| import chalk from 'chalk'; | ||
|
|
||
| import { ApifyCommand } from '../../lib/command-framework/apify-command.js'; | ||
| import { Args } from '../../lib/command-framework/args.js'; | ||
| import { CommandExitCodes } from '../../lib/consts.js'; | ||
| import { error, success } from '../../lib/outputs.js'; | ||
| import { getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js'; | ||
|
|
||
| export class TaskPublishCommand extends ApifyCommand<typeof TaskPublishCommand> { | ||
| static override name = 'publish' as const; | ||
|
|
||
| static override description = | ||
| 'Publishes the task on its public landing page.\n' + | ||
| 'The task must belong to a public Actor and have its public display configuration set up ' + | ||
|
katzino marked this conversation as resolved.
|
||
| '(in Apify Console, on the task Publication tab). ' + | ||
|
Janjiran marked this conversation as resolved.
Outdated
|
||
| 'Requires write access to the task and to its Actor.'; | ||
|
|
||
| static override examples = [ | ||
| { | ||
| description: 'Publish a task by name.', | ||
| command: 'apify task publish my-task', | ||
| }, | ||
| { | ||
| description: 'Publish a task by its full name.', | ||
| command: 'apify task publish username/my-task', | ||
| }, | ||
| ]; | ||
|
|
||
| static override docsUrl = 'https://docs.apify.com/cli/docs/reference#apify-task-publish'; | ||
|
|
||
| static override args = { | ||
| taskId: Args.string({ | ||
| required: true, | ||
| description: 'Name of the Task to publish, or its full name (e.g. "my-task" or "username/my-task").', | ||
|
Janjiran marked this conversation as resolved.
Outdated
|
||
| }), | ||
| }; | ||
|
|
||
| async run() { | ||
| const apifyClient = await getLoggedClientOrThrow(); | ||
| const userInfo = await getLocalUserInfo(); | ||
| const usernameOrId = userInfo.username || (userInfo.id as string); | ||
|
|
||
| const { taskId } = this.args; | ||
| const idOrName = taskId.includes('/') ? taskId : `${usernameOrId}/${taskId.toLowerCase()}`; | ||
| const taskClient = apifyClient.task(idOrName); | ||
|
|
||
| const task = await taskClient.get(); | ||
| if (!task) { | ||
| error({ message: `Cannot find Task with name '${taskId}' in your account.` }); | ||
| process.exitCode = CommandExitCodes.NotFound; | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await taskClient.publish(); | ||
|
|
||
| success({ | ||
| message: `Task ${chalk.yellow(task.name)} has been published.`, | ||
| stdout: true, | ||
| }); | ||
| } catch (err) { | ||
| const casted = err as ApifyApiError; | ||
|
|
||
| error({ | ||
|
katzino marked this conversation as resolved.
|
||
| message: `Failed to publish Task ${chalk.yellow(task.name)}\n ${casted.message || casted}`, | ||
|
Janjiran marked this conversation as resolved.
Outdated
|
||
| }); | ||
| process.exitCode = CommandExitCodes.RunFailed; | ||
| } | ||
| } | ||
| } | ||
|
Janjiran marked this conversation as resolved.
|
This file contains hidden or 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,70 @@ | ||
| import type { ApifyApiError } from 'apify-client'; | ||
| import chalk from 'chalk'; | ||
|
|
||
| import { ApifyCommand } from '../../lib/command-framework/apify-command.js'; | ||
| import { Args } from '../../lib/command-framework/args.js'; | ||
| import { CommandExitCodes } from '../../lib/consts.js'; | ||
| import { error, success } from '../../lib/outputs.js'; | ||
| import { getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js'; | ||
|
|
||
| export class TaskUnpublishCommand extends ApifyCommand<typeof TaskUnpublishCommand> { | ||
| static override name = 'unpublish' as const; | ||
|
|
||
| static override description = | ||
| 'Unpublishes the task from its public landing page.\n' + | ||
| 'The public display configuration is preserved, so the task can be published again later. ' + | ||
| 'Requires write access to the task and to its Actor.'; | ||
|
|
||
| static override examples = [ | ||
| { | ||
| description: 'Unpublish a task by name.', | ||
| command: 'apify task unpublish my-task', | ||
| }, | ||
| { | ||
| description: 'Unpublish a task by its full name.', | ||
|
Janjiran marked this conversation as resolved.
Outdated
|
||
| command: 'apify task unpublish username/my-task', | ||
| }, | ||
| ]; | ||
|
|
||
| static override docsUrl = 'https://docs.apify.com/cli/docs/reference#apify-task-unpublish'; | ||
|
|
||
| static override args = { | ||
| taskId: Args.string({ | ||
| required: true, | ||
| description: 'Name of the Task to unpublish, or its full name (e.g. "my-task" or "username/my-task").', | ||
|
Janjiran marked this conversation as resolved.
Outdated
|
||
| }), | ||
| }; | ||
|
|
||
| async run() { | ||
| const apifyClient = await getLoggedClientOrThrow(); | ||
| const userInfo = await getLocalUserInfo(); | ||
| const usernameOrId = userInfo.username || (userInfo.id as string); | ||
|
|
||
| const { taskId } = this.args; | ||
| const idOrName = taskId.includes('/') ? taskId : `${usernameOrId}/${taskId.toLowerCase()}`; | ||
| const taskClient = apifyClient.task(idOrName); | ||
|
|
||
| const task = await taskClient.get(); | ||
| if (!task) { | ||
| error({ message: `Cannot find Task with name '${taskId}' in your account.` }); | ||
| process.exitCode = CommandExitCodes.NotFound; | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await taskClient.unpublish(); | ||
|
|
||
| success({ | ||
| message: `Task ${chalk.yellow(task.name)} has been unpublished.`, | ||
| stdout: true, | ||
| }); | ||
| } catch (err) { | ||
| const casted = err as ApifyApiError; | ||
|
|
||
| error({ | ||
| message: `Failed to unpublish Task ${chalk.yellow(task.name)}\n ${casted.message || casted}`, | ||
| }); | ||
| process.exitCode = CommandExitCodes.RunFailed; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.