File size: 770 Bytes
9284ad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {AsyncLocalStorage} from 'async_hooks'

export interface PRIXContext {
  probotContext: any
  octokit: any
  repo: {
    owner: string
    repo: string
  }
  workingDir?: string
}

// Global context storage for current execution thread
export const als = new AsyncLocalStorage<PRIXContext>()

/**

 * Access the current execution context safely from anywhere in the codebase.

 */
export const getCurrentContext = (): PRIXContext | undefined => {
  return als.getStore()
}

/**

 * Helper to get octokit from current context

 */
export const getSafeOctokit = (): any => {
  return als.getStore()?.octokit
}

/**

 * Helper to get repo info from current context

 */
export const getSafeRepo = () => {
  return als.getStore()?.repo
}