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

Add --gpt-prompt flag to provide a prompt ready to be used with a GPT engine #314

Merged
merged 1 commit into from
Oct 30, 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
6 changes: 6 additions & 0 deletions src/cli/merge_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ struct CreateMergeRequest {
/// Accept the default title, description, and target branch
#[clap(long, short)]
pub auto: bool,
/// Provide a GPT prompt with the summary of the outgoing changes. This can
/// be used to automatically create a title and a description for the
/// outgoing merge request. Requires `--summary short` or `--summary long`.
#[clap(long, short, requires = "summary")]
pub gpt_prompt: bool,
/// Automatically fetch the latest changes from the remote repository
#[clap(long, value_name = "REMOTE_ALIAS")]
pub fetch: Option<String>,
Expand Down Expand Up @@ -292,6 +297,7 @@ impl From<CreateMergeRequest> for MergeRequestOptions {
.dry_run(options.dry_run)
.summary(options.summary.into())
.patch(options.patch)
.gpt_prompt(options.gpt_prompt)
.build()
.unwrap(),
)
Expand Down
26 changes: 26 additions & 0 deletions src/cmds/merge_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ use std::{
use super::common::{self, get_user};
use super::project::{Member, Project};

/// GPT_PROMPT is a template for the GPT prompt to generate a merge request
/// description given a list of commit messages.
const GPT_PROMPT: &str = r#"
Act like a professional software engineer. You have finished a new feature and
want to create a new pull request for someone else to review your changes. You
will be provided by a list of commit messages with the following format:

- Newest commit is at the very bottom.
- The subject of the commit message is followed by a dash `-` and its short SHA.
- If there is a body, it will be immediately below the subject `-` short SHA line.

You will provide a description of these changes. The description must not
mention commit SHAs and it must not mention the number of commits included. Be
concise and provide at most two paragraphs describing the changes. Use
imperative mode, be short and to the point. The description for the pull
request will begin with the sentence `This merge request`.

Once you have finished, then provide a title for it.

Below are the changes:"#;

#[derive(Builder, Clone, Debug, Default)]
#[builder(default)]
pub struct MergeRequestResponse {
Expand Down Expand Up @@ -199,6 +220,8 @@ pub struct MergeRequestCliArgs {
pub summary: SummaryOptions,
#[builder(default)]
pub patch: bool,
#[builder(default)]
pub gpt_prompt: bool,
}

#[derive(Clone, Debug, Default, PartialEq)]
Expand Down Expand Up @@ -671,6 +694,9 @@ fn summary(mr_body: MergeRequestBody, cli_args: &MergeRequestCliArgs) -> Result<
)
.into());
}
if cli_args.gpt_prompt {
println!("{}", GPT_PROMPT);
}
println!("\n{}", outgoing_commits);
Ok(())
}
Expand Down