Skip to content

Commit

Permalink
Add open support for CI Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
kadiryazici committed Feb 28, 2024
1 parent 6d9159a commit 979ab55
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
15 changes: 1 addition & 14 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,7 @@ tauri-build = { version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
tauri = { version = "1.2.4", features = [
"dialog-confirm",
"http-request",
"icon-ico",
"icon-png",
"macos-private-api",
"notification-all",
"os-all",
"process-exit",
"process-relaunch",
"shell-open",
"system-tray",
"updater"
] }
tauri = { version = "1.2.4", features = ["dialog-confirm", "http-request", "icon-ico", "icon-png", "macos-private-api", "notification-all", "os-all", "process-exit", "process-relaunch", "shell-open", "system-tray", "updater"] }
window-vibrancy = "0.3.2"
tiny_http = "0.12.0"
ascii = "1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/pages/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ItemRenderList } from 'vue-selectable-items'
import { useStore } from '../stores/store'
import NotificationItem from '../components/NotificationItem.vue'
import { type MinimalRepository, type Thread, markNotificationAsRead, unsubscribeNotification } from '../api/notifications'
import { toGithubWebURL } from '../utils/github'
import { createGithubWebURL } from '../utils/github'
import { AppStorage } from '../storage'
import NotificationSkeleton from '../components/NotificationSkeleton.vue'
import { useElementNavigation } from '../composables/useElementNavigation'
Expand All @@ -29,7 +29,7 @@ if (route.state.fetchOnEnter)
store.fetchNotifications(true)
function handleOpenNotification(thread: Thread) {
const url = toGithubWebURL({ notification: thread, userId: AppStorage.get('user')!.id })
const url = createGithubWebURL({ notification: thread, userId: AppStorage.get('user')!.id })
open(url)
}
Expand Down
39 changes: 24 additions & 15 deletions src/utils/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GITHUB_AUTHORIZE_ENDPOINT, GITHUB_AUTH_SCOPES } from '../api/constants'
import type { Thread } from '../api/notifications'
import { NotificationSubject } from '../constants'
import { NotificationReason, NotificationSubject } from '../constants'
import { createURL } from './url'

const NOTIFICATION_REFERRER_ID_KEY = 'notification_referrer_id'
Expand All @@ -13,33 +13,42 @@ export function createNotificationReferrerId(
return window.btoa(`018:NotificationThread${notificationId}:${userId}`)
}

export type ToGithubWebURLArgs = {
export type CreateGithubWebUrlParams = {
notification: Thread
userId: number
}

export function toGithubWebURL({ notification, userId }: ToGithubWebURLArgs) {
export function createGithubWebURL({ notification, userId }: CreateGithubWebUrlParams) {
const notificationReferrerId = createNotificationReferrerId(notification.id, userId)

let url: string

if (notification.subject.type === NotificationSubject.Discussion) {
let newURL = `https://github.com/${notification.repository.full_name}/discussions`
url = `https://github.com/${notification.repository.full_name}/discussions`
url += `?${DISCUSSIONS_QUERY_KEY}=${decodeURIComponent(notification.subject.title)}`
}
else if (notification.reason === NotificationReason.CiActivity) {
// We cannot produce link to CiActivity so target to repo name
url = `https://github.com/${notification.repository.full_name}`
}
else {
url = notification.subject.url.replace('api.github.com/repos', 'github.com')

newURL = `?${newURL}&${DISCUSSIONS_QUERY_KEY}=${decodeURIComponent(notification.subject.title)}`
if (url.includes('/pulls/'))
url = url.replace('/pulls/', '/pull/')

return newURL
if (url.includes('/releases/')) {
url = url.replace('/repos', '')
url = url.slice(0, url.lastIndexOf('/'))
}
}

let newUrl = notification.subject.url.replace('api.github.com/repos', 'github.com')
const refer = `${NOTIFICATION_REFERRER_ID_KEY}=${notificationReferrerId}`

if (newUrl.includes('/pulls/'))
newUrl = newUrl.replace('/pulls/', '/pull/')

if (newUrl.includes('/releases/')) {
newUrl = newUrl.replace('/repos', '')
newUrl = newUrl.slice(0, newUrl.lastIndexOf('/'))
}
if (url.includes('?'))
return `${url}&${refer}`

return `${newUrl}?${NOTIFICATION_REFERRER_ID_KEY}=${notificationReferrerId}`
return `${url}?${refer}`
}

export function createAuthURL(port: number) {
Expand Down

0 comments on commit 979ab55

Please sign in to comment.