Skip to main content

PullRequest

Struct PullRequest 

Source
pub struct PullRequest {
    pub title: String,
    pub body: String,
    pub milestone: Option<Milestone>,
    pub author: Option<Person>,
    pub commits: Vec<PullCommit>,
}
Expand description

A pull request, as gh pr view --json title,body,milestone,author,commits gives it.

Fields§

§title: String

The title. The squash commit gets it, and the number.

§body: String

The body. The squash commit gets it as its message.

§milestone: Option<Milestone>

The milestone, or None.

§author: Option<Person>

The author of the pull request. The squash commit is its work, so it is not a co-author.

§commits: Vec<PullCommit>

The commits of the pull request.

Implementations§

Source§

impl PullRequest

Source

pub fn new(title: &str, body: &str, milestone: Option<&str>) -> Self

A pull request with a title, a body and a milestone, and no co-author.

Source

pub fn by(self, author: Person) -> Self

The same pull request with author as its author.

Source

pub fn with_commit_by(self, author: Person) -> Self

The same pull request with one more commit by author.

Source

pub fn co_authors(&self) -> Vec<String>

The lines Co-authored-by: Name <email> that GitHub adds to the squash commit: one for each author of a commit, except the author of the pull request, and each one once.

use hygiene::{Person, PullRequest};
let person = |login: &str, name: &str, email: &str| Person {
    login: login.into(),
    name: name.into(),
    email: email.into(),
};
let pr = PullRequest::new("T", "Text.", None)
    .by(person("ana", "Ana", "ana@example.com"))
    .with_commit_by(person("ana", "Ana", "ana@example.com"))
    .with_commit_by(person("", "GLM-5.3-Flash", "noreply@z.ai"))
    .with_commit_by(person("", "GLM-5.3-Flash", "noreply@z.ai"));
assert_eq!(pr.co_authors(), ["Co-authored-by: GLM-5.3-Flash <noreply@z.ai>"]);
Source

pub fn squash_message(&self) -> String

The message that the squash will make from the body: the body, with each line over MERGE_WIDTH wrapped as the merge wraps it (merge_wrap), then the lines of PullRequest::co_authors in a paragraph of their own. GitHub adds them after a blank line, also when the body ends with trailers.

use hygiene::{Person, PullRequest};
let glm = Person { name: "GLM".into(), email: "noreply@z.ai".into(), ..Person::default() };
let pr = PullRequest::new("T", "Text.\n\nIssue: #7\n", None).with_commit_by(glm);
assert_eq!(
    pr.squash_message(),
    "Text.\n\nIssue: #7\n\nCo-authored-by: GLM <noreply@z.ai>\n"
);

Trait Implementations§

Source§

impl Clone for PullRequest

Source§

fn clone(&self) -> PullRequest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PullRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PullRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for PullRequest

Source§

fn eq(&self, other: &PullRequest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PullRequest

Source§

impl StructuralPartialEq for PullRequest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,