Skip to content
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
16 changes: 16 additions & 0 deletions src/api/current.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Get data about the currently authenticated user.

use crate::models::UpdateUserProfile;
use crate::{
models::{self, gists::Gist, orgs::MembershipInvitation, Installation, Repository},
Octocrab, Page, Result,
Expand All @@ -25,6 +26,21 @@ impl<'octo> CurrentAuthHandler<'octo> {
self.crab.get("/user", None::<&()>).await
}

/// ### Update the authenticated user
///
///works with the following fine-grained token types:
///
/// * [GitHub App user access tokens](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app)
/// * [Fine-grained personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token)
///
/// The fine-grained token must have the following permission set:
///
/// * "Profile" user permissions (write)
pub async fn update_user(&self, new_data: UpdateUserProfile) -> Result<models::Author> {
let params = serde_json::to_value(new_data).unwrap();
self.crab.patch("/user", Some(&params)).await
}

/// Fetches information about the currently authenticated app.
///
/// ```no_run
Expand Down
15 changes: 15 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,21 @@ pub struct UserProfile {
pub updated_at: DateTime<Utc>,
}

/// Data for updating a user profile,
/// e.g. name, email, company, location, bio, blog, twitter, hireable
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct UpdateUserProfile {
pub name: Option<String>,
pub email: Option<String>,
pub blog: Option<String>,
pub twitter_username: Option<String>,
pub company: Option<String>,
pub location: Option<String>,
pub hireable: Option<bool>,
pub bio: Option<String>,
}

/// The simple profile for a GitHub user
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
Expand Down
Loading