-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repos: Add support for merging branches (#336)
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,16 @@ | ||
use octocrab::Octocrab; | ||
|
||
#[tokio::main] | ||
async fn main() -> octocrab::Result<()> { | ||
let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); | ||
|
||
let octocrab = Octocrab::builder().personal_token(token).build()?; | ||
octocrab | ||
.repos("XAMPPRocky", "octocrab") | ||
.merge("feature/1", "master") | ||
.commit_message("This is a custom merge-commit message") | ||
.send() | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains 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 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,42 @@ | ||
use super::*; | ||
|
||
#[derive(serde::Serialize)] | ||
pub struct MergeBranchBuilder<'octo, 'r> { | ||
#[serde(skip)] | ||
handler: &'r RepoHandler<'octo>, | ||
head: String, | ||
base: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
commit_message: Option<String>, | ||
} | ||
|
||
impl<'octo, 'r> MergeBranchBuilder<'octo, 'r> { | ||
pub fn new( | ||
handler: &'r RepoHandler<'octo>, | ||
head: impl Into<String>, | ||
base: impl Into<String>, | ||
) -> Self { | ||
Self { | ||
handler, | ||
head: head.into(), | ||
base: base.into(), | ||
commit_message: None, | ||
} | ||
} | ||
|
||
/// The message to use for the merge commit. | ||
pub fn commit_message(mut self, commit_message: impl Into<String>) -> Self { | ||
self.commit_message = Some(commit_message.into()); | ||
self | ||
} | ||
|
||
/// Sends the actual request. | ||
pub async fn send(self) -> Result<models::repos::MergeCommit> { | ||
let route = format!( | ||
"/repos/{owner}/{repo}/merges", | ||
owner = self.handler.owner, | ||
repo = self.handler.repo | ||
); | ||
self.handler.crab.post(route, Some(&self)).await | ||
} | ||
} |
This file contains 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