-
Notifications
You must be signed in to change notification settings - Fork 2
feat(DCP-2190): add collection publish command #289
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
Merged
keyboSlice
merged 5 commits into
main
from
feat/DCP-2190-aitb-x-gmu-slice-3-collection-publish-command
Jan 30, 2026
+1,141
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ead92d
feat(DCP-2190): add collection publish command
script-this 4af0e47
feat(DCP-2190): Add AI Task Builder collection study configuration ex…
keyboSlice 225a002
feat(DCP-2190): Allow passing of a template path on collection publis…
keyboSlice eb5ac09
Merge branch 'main' into feat/DCP-2190-aitb-x-gmu-slice-3-collection-…
keyboSlice 0fd00f1
fix(DCP-2190): Allow all publish args to override template values on …
keyboSlice 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| package collection | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
|
|
||
| "github.com/prolific-oss/cli/client" | ||
| "github.com/prolific-oss/cli/cmd/shared" | ||
| "github.com/prolific-oss/cli/model" | ||
| "github.com/prolific-oss/cli/ui" | ||
| studyui "github.com/prolific-oss/cli/ui/study" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| // PublishOptions is the options for the publish collection command. | ||
| type PublishOptions struct { | ||
| Args []string | ||
| Participants int | ||
| Name string | ||
| Description string | ||
| TemplatePath string | ||
| } | ||
|
|
||
| // NewPublishCommand creates a new `collection publish` command to publish | ||
| // a collection as a study. | ||
| func NewPublishCommand(c client.API, w io.Writer) *cobra.Command { | ||
| var opts PublishOptions | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "publish <collection-id>", | ||
| Args: cobra.MinimumNArgs(1), | ||
| Short: "Publish a collection as a study", | ||
| Long: `Publish a collection as a study | ||
|
|
||
| This command creates and publishes a study from an AI Task Builder Collection. | ||
| The study will be created with the collection's content and made available | ||
| to participants. | ||
|
|
||
| You can either specify the number of participants directly, or provide a study | ||
| template file. When using a template, the collection ID will be automatically | ||
| set as the data_collection_id and data_collection_method will be set to | ||
| AI_TASK_BUILDER_COLLECTION. | ||
|
|
||
| When using a template, CLI flags (--participants, --name, --description) will | ||
| override the corresponding template values.`, | ||
| Example: ` | ||
| Publish a collection with 100 participants: | ||
|
|
||
| $ prolific collection publish 67890abcdef --participants 100 | ||
|
|
||
| Publish with a custom study name: | ||
|
|
||
| $ prolific collection publish 67890abcdef -p 50 --name "My Custom Study" | ||
|
|
||
| Publish using a study template file: | ||
|
|
||
| $ prolific collection publish 67890abcdef -t /path/to/study-template.json | ||
|
|
||
| Publish using a template but override the participant count: | ||
|
|
||
| $ prolific collection publish 67890abcdef -t /path/to/template.json -p 200 | ||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| opts.Args = args | ||
|
|
||
| if len(opts.Args) < 1 || opts.Args[0] == "" { | ||
| return errors.New("please provide a collection ID") | ||
| } | ||
|
|
||
| if opts.TemplatePath == "" && opts.Participants <= 0 { | ||
| return errors.New("please provide a valid number of participants using --participants or -p, or provide a template file using --template or -t") | ||
| } | ||
|
|
||
| return publishCollection(c, opts, w) | ||
| }, | ||
| } | ||
|
|
||
| flags := cmd.Flags() | ||
| flags.IntVarP(&opts.Participants, "participants", "p", 0, "Number of participants required (required if no template)") | ||
| flags.StringVarP(&opts.Name, "name", "n", "", "Study name (defaults to collection's task name)") | ||
| flags.StringVarP(&opts.Description, "description", "d", "", "Study description (defaults to collection's task introduction)") | ||
| flags.StringVarP(&opts.TemplatePath, "template", "t", "", "Path to a study template file (JSON/YAML) - collection ID and method will be set automatically") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func publishCollection(c client.API, opts PublishOptions, w io.Writer) error { | ||
| collectionID := opts.Args[0] | ||
|
|
||
| // Fetch the collection to get default name/description | ||
| coll, err := c.GetCollection(collectionID) | ||
| if err != nil { | ||
| if shared.IsFeatureNotEnabledError(err) { | ||
| ui.RenderFeatureAccessMessage(FeatureNameAITBCollection, FeatureContactURLAITBCollection) | ||
| return nil | ||
| } | ||
| return fmt.Errorf("failed to get collection: %s", err.Error()) | ||
| } | ||
|
|
||
| var createStudy model.CreateStudy | ||
|
|
||
| if opts.TemplatePath != "" { | ||
| // Load study configuration from template file | ||
| v := viper.New() | ||
| v.SetConfigFile(opts.TemplatePath) | ||
| if err := v.ReadInConfig(); err != nil { | ||
| return fmt.Errorf("failed to read template file: %s", err.Error()) | ||
| } | ||
|
|
||
| if err := v.Unmarshal(&createStudy); err != nil { | ||
| return fmt.Errorf("failed to parse template file: %s", err.Error()) | ||
| } | ||
|
|
||
| // Override collection-specific fields | ||
| createStudy.DataCollectionMethod = model.DataCollectionMethodAITBCollection | ||
| createStudy.DataCollectionID = collectionID | ||
| // Clear external_study_url as it's incompatible with data collection method | ||
| createStudy.ExternalStudyURL = "" | ||
|
|
||
| // Allow CLI flags to override template values | ||
| if opts.Name != "" { | ||
| createStudy.Name = opts.Name | ||
| createStudy.InternalName = opts.Name | ||
| } | ||
| if opts.Description != "" { | ||
| createStudy.Description = opts.Description | ||
| } | ||
keyboSlice marked this conversation as resolved.
Show resolved
Hide resolved
keyboSlice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if opts.Participants > 0 { | ||
| createStudy.TotalAvailablePlaces = opts.Participants | ||
| } | ||
keyboSlice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Use collection's task introduction as description if not provided in template or flags | ||
| if createStudy.Description == "" && coll.TaskDetails != nil { | ||
| createStudy.Description = coll.TaskDetails.TaskIntroduction | ||
| } | ||
| // Final fallback if still no description | ||
| if createStudy.Description == "" { | ||
| createStudy.Description = fmt.Sprintf("Study for collection: %s", coll.Name) | ||
| } | ||
| } else { | ||
| // Use collection details as defaults if not provided | ||
| studyName := opts.Name | ||
| if studyName == "" && coll.TaskDetails != nil { | ||
| studyName = coll.TaskDetails.TaskName | ||
| } | ||
| if studyName == "" { | ||
| studyName = coll.Name | ||
| } | ||
|
|
||
| studyDescription := opts.Description | ||
| if studyDescription == "" && coll.TaskDetails != nil { | ||
| studyDescription = coll.TaskDetails.TaskIntroduction | ||
| } | ||
| if studyDescription == "" { | ||
| studyDescription = fmt.Sprintf("Study for collection: %s", coll.Name) | ||
| } | ||
|
|
||
| // Create the study with collection-specific configuration | ||
| createStudy = model.CreateStudy{ | ||
| Name: studyName, | ||
| InternalName: studyName, | ||
| Description: studyDescription, | ||
| TotalAvailablePlaces: opts.Participants, | ||
| DataCollectionMethod: model.DataCollectionMethodAITBCollection, | ||
| DataCollectionID: collectionID, | ||
| } | ||
| } | ||
|
|
||
| study, err := c.CreateStudy(createStudy) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create study: %s", err.Error()) | ||
| } | ||
|
|
||
| // Transition the study to publish | ||
| _, err = c.TransitionStudy(study.ID, model.TransitionStudyPublish) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to publish study: %s", err.Error()) | ||
| } | ||
|
|
||
| // Fetch the updated study to get the latest status | ||
| study, err = c.GetStudy(study.ID) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get study details: %s", err.Error()) | ||
| } | ||
|
|
||
| // Display the result | ||
| fmt.Fprintln(w, studyui.RenderStudy(*study)) | ||
| fmt.Fprintf(w, "\nStudy URL: %s\n", studyui.GetStudyURL(study.ID)) | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought.. if earlier we have
cobraMinimumNArgs(1)us this additional check even required?