@brunolemos/devhub-core 0.102.1-rc.0 → 0.103.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/github/events.d.ts +9 -2
- package/dist/helpers/github/events.js +108 -4
- package/dist/helpers/github/events.js.map +1 -1
- package/dist/helpers/github/issues.d.ts +4 -4
- package/dist/helpers/github/issues.js +1 -4
- package/dist/helpers/github/issues.js.map +1 -1
- package/dist/helpers/github/notifications.d.ts +1 -1
- package/dist/helpers/github/notifications.js +2 -1
- package/dist/helpers/github/notifications.js.map +1 -1
- package/dist/helpers/github/shared.d.ts +13 -13
- package/dist/helpers/github/shared.js +6 -3
- package/dist/helpers/github/shared.js.map +1 -1
- package/dist/helpers/oauth.js.map +1 -1
- package/dist/helpers/shared.js +7 -5
- package/dist/helpers/shared.js.map +1 -1
- package/dist/helpers/state.d.ts +2 -2
- package/dist/helpers/state.js +1 -0
- package/dist/helpers/state.js.map +1 -1
- package/dist/mappers/notifications.js +1 -1
- package/dist/mappers/notifications.js.map +1 -1
- package/dist/mappers/repository.js +4 -0
- package/dist/mappers/repository.js.map +1 -1
- package/dist/styles/helpers.d.ts +1 -1
- package/dist/types/devhub.d.ts +4 -1
- package/dist/types/github.d.ts +6 -4
- package/dist/utils/constants.js.map +1 -1
- package/package.json +4 -4
- package/src/helpers/filters.ts +1 -1
- package/src/helpers/github/events.ts +156 -10
- package/src/helpers/github/issues.ts +2 -4
- package/src/helpers/github/notifications.ts +5 -4
- package/src/helpers/github/shared.ts +28 -30
- package/src/helpers/oauth.ts +4 -3
- package/src/helpers/shared.ts +27 -32
- package/src/types/devhub.ts +18 -9
- package/src/types/github.ts +16 -3
- package/src/utils/constants.ts +4 -5
- package/tsconfig.tsbuildinfo +0 -6827
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAEA,MAAM,GAAG,GAAG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A;AAEvC,QAAA,WAAW,GAAG,YAAY,CAAA;AAC1B,QAAA,aAAa,GAAG,eAAe,CAAA;AAE/B,QAAA,YAAY,GAAG,2BAA2B,CAAA;AAC1C,QAAA,eAAe,GAAG,4BAA4B,CAAA;AAC9C,QAAA,YAAY,GAAG,2BAA2B,CAAA;AAC1C,QAAA,gBAAgB,GAAG,GAAG,oBAAY,UAAU,CAAA;AAEzD,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AACnC,QAAA,YAAY,GAAG;IAC1B,iBAAiB,EAAE,gBAAgB;IACnC,YAAY,EAAE,GAAG,gBAAgB,UAAU;IAC3C,aAAa,EAAE,GAAG,gBAAgB,WAAW;IAC7C,YAAY,EAAE,GAAG,gBAAgB,UAAU;IAC3C,cAAc,EAAE,GAAG,gBAAgB,YAAY;IAC/C,gBAAgB,EAAE,6BAA6B;IAC/C,iBAAiB,EAAE,qCAAqC;IACxD,eAAe,EAAE,gCAAgC;CAClD,CAAA;AAEY,QAAA,oBAAoB,GAAG,QAAQ,CAAA;AAC/B,QAAA,kBAAkB,GAAG;IAChC,YAAY,EAAE,GAAG,4BAAoB,iBAAiB;IACtD,WAAW,EAAE,GAAG,4BAAoB,gBAAgB;IACpD,OAAO,EAAE,GAAG,4BAAoB,YAAY;IAC5C,KAAK,EAAE,GAAG,4BAAoB,UAAU;IACxC,SAAS,EAAE,GAAG,4BAAoB,aAAa;CAChD,CAAA;AAED,kBAAkB;AACL,QAAA,WAAW,GAAG,EAAE,CAAA;AAE7B,kBAAkB;AACL,QAAA,SAAS,GAAG,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brunolemos/devhub-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.103.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"@types/lodash": "4.14.165",
|
|
29
29
|
"@types/qs": "6.9.0",
|
|
30
30
|
"mkdirp": "0.5.1",
|
|
31
|
-
"prettier": "2.
|
|
31
|
+
"prettier": "2.3.1",
|
|
32
32
|
"shx": "0.3.3",
|
|
33
|
-
"typescript": "4.
|
|
33
|
+
"typescript": "4.3.4"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"eslint": "*"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
package/src/helpers/filters.ts
CHANGED
|
@@ -62,7 +62,7 @@ export const filterRecordWithThisValueCount = (
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function itemPassesFilterRecord<
|
|
65
|
-
F extends Record<string, boolean | undefined
|
|
65
|
+
F extends Record<string, boolean | undefined>,
|
|
66
66
|
>(filtersRecord: F, value: keyof F, defaultValue: boolean) {
|
|
67
67
|
if (!(filtersRecord && value)) return defaultValue
|
|
68
68
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
1
2
|
import immer from 'immer'
|
|
2
3
|
import _ from 'lodash'
|
|
3
4
|
import moment from 'moment'
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
EnhancedGitHubEvent,
|
|
8
|
+
EnhancementCache,
|
|
9
|
+
EventPayloadEnhancement,
|
|
7
10
|
GenericIconProp,
|
|
8
11
|
GitHubComment,
|
|
9
12
|
GitHubCommitCommentEvent,
|
|
@@ -473,11 +476,14 @@ export function getEventMetadata(
|
|
|
473
476
|
subjectType,
|
|
474
477
|
}
|
|
475
478
|
|
|
479
|
+
case 'merged':
|
|
476
480
|
case 'closed': {
|
|
477
|
-
const isMerged =
|
|
478
|
-
event.payload.
|
|
479
|
-
|
|
480
|
-
|
|
481
|
+
const isMerged =
|
|
482
|
+
event.payload.action === 'merged' ||
|
|
483
|
+
!!(
|
|
484
|
+
event.payload.pull_request.merged ||
|
|
485
|
+
event.payload.pull_request.merged_at
|
|
486
|
+
)
|
|
481
487
|
|
|
482
488
|
return {
|
|
483
489
|
action: isMerged ? 'merged' : 'closed',
|
|
@@ -924,6 +930,8 @@ export function mergeEventPreservingEnhancement(
|
|
|
924
930
|
any
|
|
925
931
|
> = {
|
|
926
932
|
enhanced: existingItem.enhanced,
|
|
933
|
+
enrichedPullRequest:
|
|
934
|
+
newItem.enrichedPullRequest || existingItem.enrichedPullRequest,
|
|
927
935
|
last_read_at: _.max([existingItem.last_read_at, newItem.last_read_at]),
|
|
928
936
|
last_saved_at: _.max([existingItem.last_saved_at, newItem.last_saved_at]),
|
|
929
937
|
last_unread_at: _.max([
|
|
@@ -946,6 +954,144 @@ export function mergeEventPreservingEnhancement(
|
|
|
946
954
|
})
|
|
947
955
|
}
|
|
948
956
|
|
|
957
|
+
export function createEventsCache(
|
|
958
|
+
events: EnhancedGitHubEvent[] | undefined,
|
|
959
|
+
_cache?: EnhancementCache | undefined,
|
|
960
|
+
): EnhancementCache {
|
|
961
|
+
const cache = _cache || new Map()
|
|
962
|
+
|
|
963
|
+
if (!(events && events.length)) return cache
|
|
964
|
+
|
|
965
|
+
events.forEach((event) => {
|
|
966
|
+
if (event.enrichedPullRequest && event.enrichedPullRequest.url) {
|
|
967
|
+
if (!cache.has(event.enrichedPullRequest.url)) {
|
|
968
|
+
cache.set(event.enrichedPullRequest.url, {
|
|
969
|
+
data: event.enrichedPullRequest,
|
|
970
|
+
timestamp: new Date(event.created_at).valueOf(),
|
|
971
|
+
})
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
})
|
|
975
|
+
|
|
976
|
+
return cache
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
export async function getEventsEnhancementMap(
|
|
980
|
+
events: EnhancedGitHubEvent[],
|
|
981
|
+
{
|
|
982
|
+
cache = new Map(),
|
|
983
|
+
getGitHubPrivateTokenForRepo,
|
|
984
|
+
githubToken: _githubToken,
|
|
985
|
+
}: {
|
|
986
|
+
cache: EnhancementCache | undefined
|
|
987
|
+
getGitHubPrivateTokenForRepo: (
|
|
988
|
+
owner: string | undefined,
|
|
989
|
+
repo: string | undefined,
|
|
990
|
+
) => string | undefined
|
|
991
|
+
githubToken: string
|
|
992
|
+
},
|
|
993
|
+
): Promise<Record<string, EventPayloadEnhancement>> {
|
|
994
|
+
const promises = events.map(async (event) => {
|
|
995
|
+
if (event.enrichedPullRequest) return
|
|
996
|
+
|
|
997
|
+
const pr =
|
|
998
|
+
('pull_request' in event.payload &&
|
|
999
|
+
(event.payload as any).pull_request) ||
|
|
1000
|
+
undefined
|
|
1001
|
+
if (!(pr && pr.url)) return
|
|
1002
|
+
|
|
1003
|
+
if (pr.html_url && pr.title) return
|
|
1004
|
+
|
|
1005
|
+
const repoFullName =
|
|
1006
|
+
'repo' in event && event.repo ? getRepoFullNameFromObject(event.repo) : ''
|
|
1007
|
+
const { owner, repo } = getOwnerAndRepo(repoFullName)
|
|
1008
|
+
|
|
1009
|
+
const privateToken = getGitHubPrivateTokenForRepo(owner, repo)
|
|
1010
|
+
const githubToken = privateToken || _githubToken
|
|
1011
|
+
|
|
1012
|
+
const enhance: EventPayloadEnhancement = {}
|
|
1013
|
+
|
|
1014
|
+
const hasPRCache = cache.has(pr.url)
|
|
1015
|
+
const prCache = cache.get(pr.url)
|
|
1016
|
+
|
|
1017
|
+
if (
|
|
1018
|
+
!hasPRCache ||
|
|
1019
|
+
(prCache &&
|
|
1020
|
+
event.created_at &&
|
|
1021
|
+
new Date(event.created_at).valueOf() > prCache.timestamp)
|
|
1022
|
+
) {
|
|
1023
|
+
try {
|
|
1024
|
+
const { data } = await axios.get(pr.url, {
|
|
1025
|
+
headers: {
|
|
1026
|
+
Authorization: githubToken && `token ${githubToken}`,
|
|
1027
|
+
},
|
|
1028
|
+
})
|
|
1029
|
+
if (!(data && data.id)) throw new Error('Invalid response')
|
|
1030
|
+
|
|
1031
|
+
enhance.enrichedPullRequest = data
|
|
1032
|
+
enhance.enhanced = true
|
|
1033
|
+
cache.set(pr.url, { data, timestamp: Date.now() })
|
|
1034
|
+
} catch (error) {
|
|
1035
|
+
console.error('Failed to load pull request details', pr.url, error)
|
|
1036
|
+
cache.set(pr.url, false)
|
|
1037
|
+
if (!enhance.enhanced) enhance.enhanced = false
|
|
1038
|
+
return
|
|
1039
|
+
}
|
|
1040
|
+
} else if (hasPRCache) {
|
|
1041
|
+
if (prCache && prCache.data) {
|
|
1042
|
+
enhance.enrichedPullRequest = prCache.data
|
|
1043
|
+
enhance.enhanced = true
|
|
1044
|
+
} else if (!enhance.enhanced) enhance.enhanced = false
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
if (!Object.keys(enhance).length) return
|
|
1048
|
+
|
|
1049
|
+
return { id: event.id, enhance }
|
|
1050
|
+
})
|
|
1051
|
+
|
|
1052
|
+
const enhancements = await Promise.all(promises)
|
|
1053
|
+
|
|
1054
|
+
const enhancementMap: Record<string, EventPayloadEnhancement> =
|
|
1055
|
+
enhancements.reduce(
|
|
1056
|
+
(map, payload) =>
|
|
1057
|
+
payload
|
|
1058
|
+
? {
|
|
1059
|
+
...map,
|
|
1060
|
+
[payload.id]: payload.enhance,
|
|
1061
|
+
}
|
|
1062
|
+
: map,
|
|
1063
|
+
{} as Record<string, EventPayloadEnhancement>,
|
|
1064
|
+
)
|
|
1065
|
+
|
|
1066
|
+
return enhancementMap
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
export function enhanceEvents(
|
|
1070
|
+
events: (GitHubEvent | EnhancedGitHubEvent)[],
|
|
1071
|
+
enhancementMap: Record<string, EventPayloadEnhancement>,
|
|
1072
|
+
currentEnhancedEvents: EnhancedGitHubEvent[] = [],
|
|
1073
|
+
) {
|
|
1074
|
+
if (!(events && events.length)) return constants.EMPTY_ARRAY
|
|
1075
|
+
|
|
1076
|
+
return events.map((item) => {
|
|
1077
|
+
const enhanced = currentEnhancedEvents.find((e) => e.id === item.id)
|
|
1078
|
+
|
|
1079
|
+
const enhance = enhancementMap[item.id]
|
|
1080
|
+
if (!enhance) {
|
|
1081
|
+
if (!enhanced) return item
|
|
1082
|
+
return mergeEventPreservingEnhancement(
|
|
1083
|
+
item as EnhancedGitHubEvent,
|
|
1084
|
+
enhanced,
|
|
1085
|
+
)
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
return {
|
|
1089
|
+
...mergeEventPreservingEnhancement(item as EnhancedGitHubEvent, enhanced),
|
|
1090
|
+
...enhance,
|
|
1091
|
+
} as EnhancedGitHubEvent
|
|
1092
|
+
})
|
|
1093
|
+
}
|
|
1094
|
+
|
|
949
1095
|
export function getGitHubEventSubItems(
|
|
950
1096
|
event: EnhancedGitHubEvent,
|
|
951
1097
|
{ plan }: { plan: UserPlan | null | undefined },
|
|
@@ -955,18 +1101,18 @@ export function getGitHubEventSubItems(
|
|
|
955
1101
|
const { repo: _repo } = event as GitHubEvent
|
|
956
1102
|
const { repos: _repos } = event as MultipleStarEvent
|
|
957
1103
|
|
|
958
|
-
const comment:
|
|
959
|
-
|
|
960
|
-
|
|
1104
|
+
const comment: GitHubComment | undefined = (
|
|
1105
|
+
payload as GitHubCommitCommentEvent['payload']
|
|
1106
|
+
).comment
|
|
961
1107
|
const { commits: _commits } = payload as GitHubPushEvent['payload']
|
|
962
1108
|
const forkee: GitHubRepo | undefined = (payload as GitHubForkEvent['payload'])
|
|
963
1109
|
.forkee
|
|
964
1110
|
const { member: _member } = payload as GitHubMemberEvent['payload']
|
|
965
1111
|
const { release } = payload as GitHubReleaseEvent['payload']
|
|
966
1112
|
const { pages: _pages } = payload as GitHubGollumEvent['payload']
|
|
967
|
-
const {
|
|
968
|
-
|
|
969
|
-
|
|
1113
|
+
const { pull_request: _payloadPullRequest } =
|
|
1114
|
+
payload as GitHubPullRequestEvent['payload']
|
|
1115
|
+
const pullRequest = event.enrichedPullRequest || _payloadPullRequest
|
|
970
1116
|
const { issue } = payload as GitHubIssuesEvent['payload']
|
|
971
1117
|
const { ref: branchOrTagRef } = payload as GitHubPushEvent['payload']
|
|
972
1118
|
|
|
@@ -35,10 +35,8 @@ import {
|
|
|
35
35
|
getRepoUrlFromOtherUrl,
|
|
36
36
|
} from './url'
|
|
37
37
|
|
|
38
|
-
export const issueOrPullRequestSubjectTypes: GitHubIssueOrPullRequestSubjectType[] =
|
|
39
|
-
'Issue',
|
|
40
|
-
'PullRequest',
|
|
41
|
-
]
|
|
38
|
+
export const issueOrPullRequestSubjectTypes: GitHubIssueOrPullRequestSubjectType[] =
|
|
39
|
+
['Issue', 'PullRequest']
|
|
42
40
|
|
|
43
41
|
export function getIssueOrPullRequestIconAndColor(
|
|
44
42
|
type: GitHubIssueOrPullRequestSubjectType,
|
|
@@ -111,7 +111,7 @@ export function getNotificationIconAndColor(
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export function getNotificationReasonMetadata<
|
|
114
|
-
T extends EnhancedGitHubNotification['reason']
|
|
114
|
+
T extends EnhancedGitHubNotification['reason'],
|
|
115
115
|
>(
|
|
116
116
|
reason: T,
|
|
117
117
|
): {
|
|
@@ -477,9 +477,10 @@ export async function getNotificationsEnhancementMap(
|
|
|
477
477
|
enhance.pullRequest.requested_reviewers
|
|
478
478
|
) {
|
|
479
479
|
if (!enhance.requestedMyReview) {
|
|
480
|
-
enhance.requestedMyReview =
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
enhance.requestedMyReview =
|
|
481
|
+
!!enhance.pullRequest.requested_reviewers.find(
|
|
482
|
+
(u) => githubLogin === `${u.login || ''}`.toLowerCase().trim(),
|
|
483
|
+
)
|
|
483
484
|
}
|
|
484
485
|
}
|
|
485
486
|
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
GenericIconProp,
|
|
17
17
|
GitHubAPIHeaders,
|
|
18
18
|
GitHubComment,
|
|
19
|
+
GitHubEventPullRequest,
|
|
19
20
|
GitHubIssueOrPullRequest,
|
|
20
21
|
GitHubItemSubjectType,
|
|
21
22
|
GitHubPrivacy,
|
|
@@ -311,6 +312,7 @@ export function getUserAvatarFromObject(
|
|
|
311
312
|
{ size }: { size?: number } = {},
|
|
312
313
|
getPixelSizeForLayoutSizeFn: ((size: number) => number) | undefined,
|
|
313
314
|
) {
|
|
315
|
+
if (!user) return undefined
|
|
314
316
|
if (!(user.avatar_url || user.id || user.login)) return undefined
|
|
315
317
|
|
|
316
318
|
const baseURL =
|
|
@@ -337,9 +339,10 @@ export function getUserAvatarFromObject(
|
|
|
337
339
|
)
|
|
338
340
|
}
|
|
339
341
|
|
|
340
|
-
export function tryGetIdAndUsernameFromGitHubEmail(
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
export function tryGetIdAndUsernameFromGitHubEmail(email?: string): {
|
|
343
|
+
id: string | undefined
|
|
344
|
+
username: string | undefined
|
|
345
|
+
} {
|
|
343
346
|
if (!email) return { id: undefined, username: undefined }
|
|
344
347
|
|
|
345
348
|
const emailSplit = email.split('@')
|
|
@@ -399,9 +402,10 @@ export function isPullRequest(issue: {
|
|
|
399
402
|
)
|
|
400
403
|
}
|
|
401
404
|
|
|
402
|
-
export function getOwnerAndRepo(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
+
export function getOwnerAndRepo(repoFullName: string | undefined): {
|
|
406
|
+
owner: string | undefined
|
|
407
|
+
repo: string | undefined
|
|
408
|
+
} {
|
|
405
409
|
if (!repoFullName) return { owner: '', repo: '' }
|
|
406
410
|
|
|
407
411
|
const repoSplitedNames = (repoFullName || '')
|
|
@@ -769,10 +773,8 @@ export function getColumnHeaderDetails(
|
|
|
769
773
|
case 'issue_or_pr': {
|
|
770
774
|
const s = subscription as Partial<IssueOrPullRequestColumnSubscription>
|
|
771
775
|
|
|
772
|
-
const {
|
|
773
|
-
|
|
774
|
-
allIncludedRepos,
|
|
775
|
-
} = getOwnerAndRepoFormattedFilter(column.filters)
|
|
776
|
+
const { allIncludedOwners, allIncludedRepos } =
|
|
777
|
+
getOwnerAndRepoFormattedFilter(column.filters)
|
|
776
778
|
|
|
777
779
|
const owner =
|
|
778
780
|
allIncludedOwners.length === 1 ? allIncludedOwners[0] : undefined
|
|
@@ -782,13 +784,10 @@ export function getColumnHeaderDetails(
|
|
|
782
784
|
? getOwnerAndRepo(allIncludedRepos[0])
|
|
783
785
|
: { owner: undefined, repo: undefined }
|
|
784
786
|
|
|
785
|
-
const {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
} = getUsernamesFromFilter('issue_or_pr', column.filters, {
|
|
790
|
-
blacklist: ['owner'],
|
|
791
|
-
})
|
|
787
|
+
const { includedUsernames, excludedUsernames, usedUsernameFilterKeys } =
|
|
788
|
+
getUsernamesFromFilter('issue_or_pr', column.filters, {
|
|
789
|
+
blacklist: ['owner'],
|
|
790
|
+
})
|
|
792
791
|
|
|
793
792
|
const usernames =
|
|
794
793
|
(includedUsernames && includedUsernames.length
|
|
@@ -925,7 +924,7 @@ export function getColumnHeaderDetails(
|
|
|
925
924
|
}
|
|
926
925
|
|
|
927
926
|
export function createSubscriptionObjectWithId<
|
|
928
|
-
S extends Pick<ColumnSubscription, 'type' | 'subtype' | 'params'
|
|
927
|
+
S extends Pick<ColumnSubscription, 'type' | 'subtype' | 'params'>,
|
|
929
928
|
>(subscription: S) {
|
|
930
929
|
return {
|
|
931
930
|
...subscription,
|
|
@@ -934,7 +933,7 @@ export function createSubscriptionObjectWithId<
|
|
|
934
933
|
}
|
|
935
934
|
|
|
936
935
|
export function createSubscriptionObjectsWithId<
|
|
937
|
-
S extends Pick<ColumnSubscription, 'type' | 'subtype' | 'params'>[]
|
|
936
|
+
S extends Pick<ColumnSubscription, 'type' | 'subtype' | 'params'>[],
|
|
938
937
|
>(subscriptions: S) {
|
|
939
938
|
return subscriptions.map((subscription) => ({
|
|
940
939
|
...subscription,
|
|
@@ -1010,11 +1009,11 @@ export function getTagIconAndColor(): GenericIconProp & {
|
|
|
1010
1009
|
}
|
|
1011
1010
|
|
|
1012
1011
|
export function getPullRequestIconAndColor(pullRequest: {
|
|
1013
|
-
draft
|
|
1014
|
-
state
|
|
1015
|
-
merged
|
|
1016
|
-
merged_at
|
|
1017
|
-
mergeable_state
|
|
1012
|
+
draft?: GitHubPullRequest['draft']
|
|
1013
|
+
state?: GitHubPullRequest['state']
|
|
1014
|
+
merged?: GitHubPullRequest['merged']
|
|
1015
|
+
merged_at?: GitHubPullRequest['merged_at']
|
|
1016
|
+
mergeable_state?: GitHubPullRequest['mergeable_state']
|
|
1018
1017
|
}): GenericIconProp & { color?: keyof ThemeColors; tooltip: string } {
|
|
1019
1018
|
const draft = isDraft(pullRequest)
|
|
1020
1019
|
const state = getIssueOrPullRequestState(pullRequest)
|
|
@@ -1097,7 +1096,7 @@ export function getStateTypeMetadata<T extends GitHubStateType>(
|
|
|
1097
1096
|
label: string
|
|
1098
1097
|
state: T
|
|
1099
1098
|
} {
|
|
1100
|
-
switch (state
|
|
1099
|
+
switch (state) {
|
|
1101
1100
|
case 'open': {
|
|
1102
1101
|
return {
|
|
1103
1102
|
color: 'green',
|
|
@@ -1139,7 +1138,7 @@ export function getSubjectTypeMetadata<T extends GitHubItemSubjectType>(
|
|
|
1139
1138
|
label: string
|
|
1140
1139
|
subjectType: T
|
|
1141
1140
|
} {
|
|
1142
|
-
switch (subjectType
|
|
1141
|
+
switch (subjectType) {
|
|
1143
1142
|
case 'PullRequestReview': {
|
|
1144
1143
|
return {
|
|
1145
1144
|
label: 'Pull Request Review',
|
|
@@ -1225,7 +1224,7 @@ export function getItemPrivacy(
|
|
|
1225
1224
|
export function getItemIssueOrPullRequest(
|
|
1226
1225
|
type: ColumnSubscription['type'],
|
|
1227
1226
|
item: EnhancedItem | undefined,
|
|
1228
|
-
): GitHubIssueOrPullRequest | undefined {
|
|
1227
|
+
): GitHubIssueOrPullRequest | GitHubEventPullRequest | undefined {
|
|
1229
1228
|
if (!item) return undefined
|
|
1230
1229
|
|
|
1231
1230
|
switch (type) {
|
|
@@ -1624,9 +1623,8 @@ export function getItemsFilterMetadata(
|
|
|
1624
1623
|
|
|
1625
1624
|
if (subscriptionReason) {
|
|
1626
1625
|
if (!result.subscriptionReason[subscriptionReason])
|
|
1627
|
-
result.subscriptionReason[
|
|
1628
|
-
|
|
1629
|
-
] = getDefaultItemFilterCountMetadata()
|
|
1626
|
+
result.subscriptionReason[subscriptionReason] =
|
|
1627
|
+
getDefaultItemFilterCountMetadata()
|
|
1630
1628
|
updateNestedCounter(result.subscriptionReason[subscriptionReason]!)
|
|
1631
1629
|
}
|
|
1632
1630
|
|
package/src/helpers/oauth.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GitHubTokenDetails, OAuthResponseData } from '../types'
|
|
2
2
|
|
|
3
|
-
export function tryParseOAuthParams(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export function tryParseOAuthParams(params: OAuthResponseData): {
|
|
4
|
+
appToken?: string
|
|
5
|
+
tokenDetails?: GitHubTokenDetails
|
|
6
|
+
} {
|
|
6
7
|
try {
|
|
7
8
|
if (!(params && params.app_token && params.github_token))
|
|
8
9
|
throw new Error('No token received.')
|
package/src/helpers/shared.ts
CHANGED
|
@@ -224,7 +224,7 @@ export function deepMapper<T extends object, R = T>(
|
|
|
224
224
|
|
|
225
225
|
const urlsToKeep = ['url', 'html_url', 'avatar_url', 'latest_comment_url']
|
|
226
226
|
export function removeUselessURLsFromResponseItem<
|
|
227
|
-
T extends Record<string, any
|
|
227
|
+
T extends Record<string, any>,
|
|
228
228
|
>(item: T) {
|
|
229
229
|
let hasChanged = false
|
|
230
230
|
const result = deepMapper(item, (obj) => {
|
|
@@ -386,14 +386,12 @@ export function getSubscriptionOwnerOrOrg(
|
|
|
386
386
|
if ('org' in subscription.params && subscription.params.org)
|
|
387
387
|
return subscription.params.org
|
|
388
388
|
|
|
389
|
-
const {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
: undefined,
|
|
396
|
-
)
|
|
389
|
+
const { allIncludedOwners, allIncludedRepos } =
|
|
390
|
+
getOwnerAndRepoFormattedFilter(
|
|
391
|
+
'owners' in subscription.params
|
|
392
|
+
? { owners: subscription.params.owners }
|
|
393
|
+
: undefined,
|
|
394
|
+
)
|
|
397
395
|
|
|
398
396
|
const _org = allIncludedOwners.length === 1 ? allIncludedOwners[0] : undefined
|
|
399
397
|
const _ownerAndRepo =
|
|
@@ -799,10 +797,9 @@ export function getFilterFromSearchQuery(
|
|
|
799
797
|
|
|
800
798
|
case 'pr': {
|
|
801
799
|
filters.subjectTypes = filters.subjectTypes || {}
|
|
802
|
-
;(
|
|
803
|
-
GitHubItemSubjectType,
|
|
804
|
-
|
|
805
|
-
>).PullRequest = !isNegated
|
|
800
|
+
;(
|
|
801
|
+
filters.subjectTypes as Record<GitHubItemSubjectType, boolean>
|
|
802
|
+
).PullRequest = !isNegated
|
|
806
803
|
break
|
|
807
804
|
}
|
|
808
805
|
|
|
@@ -825,10 +822,12 @@ export function getFilterFromSearchQuery(
|
|
|
825
822
|
|
|
826
823
|
validSubjectTypes.forEach((subjectType) => {
|
|
827
824
|
if (subjectType.toLowerCase() === value) {
|
|
828
|
-
;(
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
825
|
+
;(
|
|
826
|
+
filters.subjectTypes as Record<
|
|
827
|
+
GitHubItemSubjectType,
|
|
828
|
+
boolean
|
|
829
|
+
>
|
|
830
|
+
)[subjectType] = !isNegated
|
|
832
831
|
}
|
|
833
832
|
})
|
|
834
833
|
break
|
|
@@ -859,9 +858,8 @@ export function getFilterFromSearchQuery(
|
|
|
859
858
|
// invalid
|
|
860
859
|
if (!eventActions.includes(action as GitHubEventAction)) return
|
|
861
860
|
|
|
862
|
-
activityFilters.activity.actions[
|
|
863
|
-
|
|
864
|
-
] = !isNegated
|
|
861
|
+
activityFilters.activity.actions[action as GitHubEventAction] =
|
|
862
|
+
!isNegated
|
|
865
863
|
break
|
|
866
864
|
}
|
|
867
865
|
|
|
@@ -916,9 +914,8 @@ export function getFilterFromSearchQuery(
|
|
|
916
914
|
)
|
|
917
915
|
return
|
|
918
916
|
|
|
919
|
-
reasonsFilter[
|
|
920
|
-
|
|
921
|
-
] = !isNegated
|
|
917
|
+
reasonsFilter[reason as EnhancedGitHubNotification['reason']] =
|
|
918
|
+
!isNegated
|
|
922
919
|
break
|
|
923
920
|
}
|
|
924
921
|
|
|
@@ -961,7 +958,7 @@ export function getValuesFromQueryKeysFilter(
|
|
|
961
958
|
}) || undefined
|
|
962
959
|
const queryTerms = getSearchQueryTerms(filtersQuery)
|
|
963
960
|
|
|
964
|
-
const filteredQueryTerms =
|
|
961
|
+
const filteredQueryTerms = _.sortBy(
|
|
965
962
|
queryTerms.filter(
|
|
966
963
|
(queryTerm) =>
|
|
967
964
|
queryTerm &&
|
|
@@ -969,7 +966,7 @@ export function getValuesFromQueryKeysFilter(
|
|
|
969
966
|
queryKeys.includes(queryTerm[0] as any),
|
|
970
967
|
),
|
|
971
968
|
['0', '2'],
|
|
972
|
-
) as any
|
|
969
|
+
) as any as [string, string, boolean][]
|
|
973
970
|
const usedQueryKeys = _.uniq(
|
|
974
971
|
filteredQueryTerms.map((queryTerm) => queryTerm[0]),
|
|
975
972
|
)
|
|
@@ -1049,12 +1046,8 @@ export function getUsernamesFromFilter(
|
|
|
1049
1046
|
) {
|
|
1050
1047
|
const usernameFilterKeys = whitelist.filter((key) => !blacklist.includes(key))
|
|
1051
1048
|
|
|
1052
|
-
const {
|
|
1053
|
-
|
|
1054
|
-
excluded,
|
|
1055
|
-
included,
|
|
1056
|
-
usedQueryKeys,
|
|
1057
|
-
} = getValuesFromQueryKeysFilter(type, usernameFilterKeys, filters)
|
|
1049
|
+
const { all, excluded, included, usedQueryKeys } =
|
|
1050
|
+
getValuesFromQueryKeysFilter(type, usernameFilterKeys, filters)
|
|
1058
1051
|
|
|
1059
1052
|
return {
|
|
1060
1053
|
allUsernames: all,
|
|
@@ -1111,7 +1104,9 @@ export function getItemsFromSubscriptions(
|
|
|
1111
1104
|
return sortNotifications(result as EnhancedGitHubNotification[])
|
|
1112
1105
|
}
|
|
1113
1106
|
|
|
1114
|
-
console.error(
|
|
1107
|
+
console.error(
|
|
1108
|
+
`Unhandled subscription type: ${((subscriptions[0] as any) || {}).type}`,
|
|
1109
|
+
)
|
|
1115
1110
|
return result
|
|
1116
1111
|
}
|
|
1117
1112
|
|
package/src/types/devhub.ts
CHANGED
|
@@ -77,6 +77,10 @@ export type IssueOrPullRequestPayloadEnhancement =
|
|
|
77
77
|
| IssuePayloadEnhancement
|
|
78
78
|
| PullRequestPayloadEnhancement
|
|
79
79
|
|
|
80
|
+
export interface EventPayloadEnhancement extends BaseEnhancement {
|
|
81
|
+
enrichedPullRequest?: GitHubPullRequest
|
|
82
|
+
}
|
|
83
|
+
|
|
80
84
|
export interface EnhancedGitHubNotification
|
|
81
85
|
extends Omit<GitHubNotification, 'reason'>,
|
|
82
86
|
NotificationPayloadEnhancement {
|
|
@@ -95,7 +99,7 @@ export interface MultipleStarEvent
|
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
export type EnhancedGitHubEvent = (GitHubEvent | MultipleStarEvent) &
|
|
98
|
-
|
|
102
|
+
EventPayloadEnhancement
|
|
99
103
|
|
|
100
104
|
export type EnhancedGitHubIssue = GitHubIssue & IssuePayloadEnhancement
|
|
101
105
|
|
|
@@ -330,15 +334,17 @@ export type GenericColumnCreation<
|
|
|
330
334
|
ColumnType extends
|
|
331
335
|
| ActivityColumn
|
|
332
336
|
| IssueOrPullRequestColumn
|
|
333
|
-
| NotificationColumn
|
|
337
|
+
| NotificationColumn,
|
|
334
338
|
> = Omit<ColumnType, 'createdAt' | 'updatedAt'> & {
|
|
335
339
|
createdAt?: string
|
|
336
340
|
updatedAt?: string
|
|
337
341
|
}
|
|
338
342
|
|
|
339
343
|
export type ActivityColumnCreation = GenericColumnCreation<ActivityColumn>
|
|
340
|
-
export type IssueOrPullRequestColumnCreation =
|
|
341
|
-
|
|
344
|
+
export type IssueOrPullRequestColumnCreation =
|
|
345
|
+
GenericColumnCreation<IssueOrPullRequestColumn>
|
|
346
|
+
export type NotificationColumnCreation =
|
|
347
|
+
GenericColumnCreation<NotificationColumn>
|
|
342
348
|
|
|
343
349
|
export type ColumnCreation =
|
|
344
350
|
| ActivityColumnCreation
|
|
@@ -349,7 +355,7 @@ export type GenericColumnSubscriptionCreation<
|
|
|
349
355
|
ColumnSubscriptionType extends
|
|
350
356
|
| ActivityColumnSubscription
|
|
351
357
|
| IssueOrPullRequestColumnSubscription
|
|
352
|
-
| NotificationColumnSubscription
|
|
358
|
+
| NotificationColumnSubscription,
|
|
353
359
|
> = Omit<ColumnSubscriptionType, 'id' | 'data' | 'createdAt' | 'updatedAt'> & {
|
|
354
360
|
id?: string | undefined
|
|
355
361
|
data?: ColumnSubscriptionType['data'] | undefined
|
|
@@ -357,9 +363,12 @@ export type GenericColumnSubscriptionCreation<
|
|
|
357
363
|
updatedAt?: string | undefined
|
|
358
364
|
}
|
|
359
365
|
|
|
360
|
-
export type ActivityColumnSubscriptionCreation =
|
|
361
|
-
|
|
362
|
-
export type
|
|
366
|
+
export type ActivityColumnSubscriptionCreation =
|
|
367
|
+
GenericColumnSubscriptionCreation<ActivityColumnSubscription>
|
|
368
|
+
export type IssueOrPullRequestColumnSubscriptionCreation =
|
|
369
|
+
GenericColumnSubscriptionCreation<IssueOrPullRequestColumnSubscription>
|
|
370
|
+
export type NotificationColumnSubscriptionCreation =
|
|
371
|
+
GenericColumnSubscriptionCreation<NotificationColumnSubscription>
|
|
363
372
|
|
|
364
373
|
export type ColumnSubscriptionCreation =
|
|
365
374
|
| ActivityColumnSubscriptionCreation
|
|
@@ -590,7 +599,7 @@ export interface Plan {
|
|
|
590
599
|
export type UserPlan = GraphQLUserPlan
|
|
591
600
|
|
|
592
601
|
export interface ItemPushNotification<
|
|
593
|
-
A extends { type: string; payload: any } = { type: string; payload: any }
|
|
602
|
+
A extends { type: string; payload: any } = { type: string; payload: any },
|
|
594
603
|
> {
|
|
595
604
|
title: string
|
|
596
605
|
subtitle?: string
|