Code Study: GitHub Desktop / lib / parse-app-url.ts

The code file defines the supported URL action types.


export type URLActionType =
  | IOAuthAction
  | IOpenRepositoryFromURLAction
  | IOpenRepositoryFromPathAction
  | IUnknownAction

export interface IOAuthAction {
  readonly name: 'oauth'
  readonly code: string
  readonly state: string

export interface IOpenRepositoryFromURLAction {
  readonly name: 'open-repository-from-url'
  /** the remote repository location associated with the "Open in Desktop" action */
  readonly url: string
  /** the optional branch name which should be checked out. use the default branch otherwise. */
  readonly branch: string | null
  /** the pull request number, if pull request originates from a fork of the repository */
  readonly pr: string | null
  /** the file to open after cloning the repository */
  readonly filepath: string | null

export interface IOpenRepositoryFromPathAction {
  readonly name: 'open-repository-from-path'
  /** The local path to open. */
  readonly path: string

export interface IUnknownAction {
  readonly name: 'unknown'
  readonly url: string

It also defines a parseAppURL function:


The function parses a given url string to one of the URL action types with extracted parameters for each URL action type.

export function parseAppURL(url: string): URLActionType

The url is in the format of: <protocol>://<actionName>/<parsedPath>?<queryStrings>. Here are the format and example url strings of each URLActionType:

FormatExample URL stringURLActionType
tags: GitHub Desktop - Electron