Skip to content

Commit 50dbab0

Browse files
authored
collab: Add renovate[bot] to the GET /contributor endpoint (#15250)
This PR adds the `renovate[bot]` user to the `GET /contributor` endpoint so that it passes the CLA check. I patched this temporarily by adding a case into the `zed.dev` endpoint the fronts this one, but I think long-term it will be better for collab to be the source of truth. Release Notes: - N/A
1 parent 70c22cb commit 50dbab0

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

crates/collab/src/api.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use axum::{
1919
Extension, Json, Router,
2020
};
2121
use axum_extra::response::ErasedJson;
22-
use chrono::SecondsFormat;
22+
use chrono::{NaiveDateTime, SecondsFormat};
2323
use serde::{Deserialize, Serialize};
24-
use std::sync::Arc;
24+
use std::sync::{Arc, OnceLock};
2525
use tower::ServiceBuilder;
2626

2727
pub use extensions::fetch_extensions_from_blob_store_periodically;
@@ -162,6 +162,17 @@ async fn check_is_contributor(
162162
Query(params): Query<CheckIsContributorParams>,
163163
) -> Result<Json<CheckIsContributorResponse>> {
164164
let params = params.as_contributor_selector()?;
165+
166+
if RenovateBot::is_renovate_bot(&params) {
167+
return Ok(Json(CheckIsContributorResponse {
168+
signed_at: Some(
169+
RenovateBot::created_at()
170+
.and_utc()
171+
.to_rfc3339_opts(SecondsFormat::Millis, true),
172+
),
173+
}));
174+
}
175+
165176
Ok(Json(CheckIsContributorResponse {
166177
signed_at: app
167178
.db
@@ -171,6 +182,36 @@ async fn check_is_contributor(
171182
}))
172183
}
173184

185+
/// The Renovate bot GitHub user (`renovate[bot]`).
186+
///
187+
/// https://api.github.com/users/renovate[bot]
188+
struct RenovateBot;
189+
190+
impl RenovateBot {
191+
const LOGIN: &'static str = "renovate[bot]";
192+
const USER_ID: i32 = 29139614;
193+
194+
/// Returns the `created_at` timestamp for the Renovate bot user.
195+
fn created_at() -> &'static NaiveDateTime {
196+
static CREATED_AT: OnceLock<NaiveDateTime> = OnceLock::new();
197+
CREATED_AT.get_or_init(|| {
198+
chrono::DateTime::parse_from_rfc3339("2017-06-02T07:04:12Z")
199+
.expect("failed to parse 'created_at' for 'renovate[bot]'")
200+
.naive_utc()
201+
})
202+
}
203+
204+
/// Returns whether the given contributor selector corresponds to the Renovate bot user.
205+
fn is_renovate_bot(contributor: &ContributorSelector) -> bool {
206+
match contributor {
207+
ContributorSelector::GitHubLogin { github_login } => github_login == Self::LOGIN,
208+
ContributorSelector::GitHubUserId { github_user_id } => {
209+
github_user_id == &Self::USER_ID
210+
}
211+
}
212+
}
213+
}
214+
174215
async fn add_contributor(
175216
Extension(app): Extension<Arc<AppState>>,
176217
extract::Json(params): extract::Json<AuthenticatedUserParams>,

0 commit comments

Comments
 (0)