Skip to content

Commit 96ff0a8

Browse files
committed
Add links to the grant access page
1 parent 67ea811 commit 96ff0a8

3 files changed

Lines changed: 45 additions & 10 deletions

File tree

src/bar.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::github::auth::GithubAuthCommand;
1+
use crate::github::auth::{GitHubAuth, GithubAuthCommand};
22
use crate::state::AppStateRef;
33
use eframe::egui;
44
use eframe::egui::{Popup, Ui};
@@ -26,6 +26,11 @@ pub fn auth_ui(ui: &mut Ui, state: &AppStateRef<'_>) {
2626
let response = ui.button(&logged_in.username);
2727

2828
Popup::menu(&response).show(|ui| {
29+
if ui.button("Manage repository access").clicked() {
30+
ui.ctx().open_url(egui::OpenUrl::new_tab(
31+
GitHubAuth::MANAGE_REPO_ACCESS_URL,
32+
));
33+
}
2934
if ui.button("Log out").clicked() {
3035
state.send(GithubAuthCommand::Logout);
3136
}

src/github/auth.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ impl GitHubAuth {
116116
const GITHUB_CLIENT_ID: &'static str = "Iv23li8RPCGatBkgBNaE";
117117
const CALLBACK_URL: &'static str =
118118
"https://kitdiff-auth-720893688618.europe-west1.run.app/callback";
119+
pub const MANAGE_REPO_ACCESS_URL: &'static str =
120+
"https://github.com/apps/kitdiff/installations/new";
119121

120122
pub fn new(state: AuthState, sender: UiInboxSender<SystemCommand>) -> Self {
121123
let this = Self {

src/viewer/file_tree.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
11
use crate::state::{FilteredSnapshot, ViewerAppStateRef, ViewerSystemCommand};
22
use eframe::egui;
3-
use eframe::egui::{Id, ScrollArea, TextEdit, Ui, Widget as _};
3+
use eframe::egui::{Id, OpenUrl, ScrollArea, TextEdit, Ui};
4+
use re_ui::UiExt as _;
5+
use re_ui::alert::Alert;
46
use re_ui::list_item::LabelContent;
5-
use re_ui::{UiExt as _, icons};
67
use std::task::Poll;
78

9+
fn is_github_permission_error(err: &anyhow::Error) -> bool {
10+
for cause in err.chain() {
11+
if let Some(github_err) = cause.downcast_ref::<octocrab::GitHubError>() {
12+
return matches!(
13+
github_err.status_code,
14+
reqwest::StatusCode::FORBIDDEN | reqwest::StatusCode::NOT_FOUND
15+
);
16+
}
17+
}
18+
// octocrab can fail to parse a 404 error body, producing a serde error instead
19+
let msg = err.to_string().to_lowercase();
20+
msg.contains("not found") || msg.contains("missing field")
21+
}
22+
823
pub fn file_tree(ui: &mut Ui, state: &ViewerAppStateRef<'_>) {
924
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate);
1025

1126
state.loader.extra_ui(ui, state.app);
1227

28+
if let Poll::Ready(Err(e)) = state.loader.state() {
29+
if is_github_permission_error(e) {
30+
Alert::warning().show(ui, |ui: &mut Ui| {
31+
ui.vertical(|ui| {
32+
ui.label("kitdiff does not have access to this repository.");
33+
if ui.link("Grant repository access").clicked() {
34+
ui.ctx().open_url(OpenUrl::new_tab(
35+
crate::github::auth::GitHubAuth::MANAGE_REPO_ACCESS_URL,
36+
));
37+
}
38+
});
39+
});
40+
} else {
41+
Alert::error().show(ui, |ui: &mut Ui| {
42+
ui.label(e.to_string());
43+
});
44+
}
45+
}
46+
1347
ui.panel_title_bar_with_buttons(&state.loader.files_header(), None, |ui| {
1448
match state.loader.state() {
1549
Poll::Ready(Ok(())) => {}
16-
Poll::Ready(Err(e)) => {
17-
icons::ERROR
18-
.as_image()
19-
.tint(ui.tokens().alert_error.icon)
20-
.ui(ui)
21-
.on_hover_text(e.to_string());
22-
}
50+
Poll::Ready(Err(_)) => {}
2351
Poll::Pending => {
2452
ui.spinner();
2553
}

0 commit comments

Comments
 (0)