1use super::*;
2
3impl Database {
4 /// Records that a given user has signed the CLA.
5 #[cfg(test)]
6 pub async fn add_contributor(
7 &self,
8 github_login: &str,
9 github_user_id: i32,
10 github_email: Option<&str>,
11 github_name: Option<&str>,
12 github_user_created_at: DateTimeUtc,
13 initial_channel_id: Option<ChannelId>,
14 ) -> Result<()> {
15 self.transaction(|tx| async move {
16 let user = self
17 .update_or_create_user_by_github_account_tx(
18 github_login,
19 github_user_id,
20 github_email,
21 github_name,
22 github_user_created_at.naive_utc(),
23 initial_channel_id,
24 &tx,
25 )
26 .await?;
27
28 contributor::Entity::insert(contributor::ActiveModel {
29 user_id: ActiveValue::Set(user.id),
30 signed_at: ActiveValue::NotSet,
31 })
32 .on_conflict(
33 OnConflict::column(contributor::Column::UserId)
34 .do_nothing()
35 .to_owned(),
36 )
37 .exec_without_returning(&*tx)
38 .await?;
39 Ok(())
40 })
41 .await
42 }
43}