Skip to content

Commit d64814a

Browse files
committed
fix: review comments
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent f34c9dd commit d64814a

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

services/apps/automatic_projects_discovery_worker/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Options, ServiceWorker } from '@crowd/archetype-worker'
44
import { scheduleProjectsDiscovery } from './schedules/scheduleProjectsDiscovery'
55

66
const config: Config = {
7-
envvars: ['CROWD_GITHUB_PERSONAL_ACCESS_TOKENS', 'LF_CRITICALITY_SCORE_API_URL'],
7+
envvars: ['CROWD_GITHUB_PERSONAL_ACCESS_TOKENS'],
88
producer: {
99
enabled: false,
1010
},

services/apps/automatic_projects_discovery_worker/src/sources/insights-discussions/source.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,34 @@ import { IDatasetDescriptor, IDiscoverySource, IDiscoverySourceRow } from '../ty
77

88
const log = getServiceLogger()
99

10+
const CATEGORY_SLUG = 'project-onboardings'
1011
const GITHUB_GRAPHQL_URL = 'https://api.github.com/graphql'
12+
const GITHUB_NON_REPO_OWNERS = new Set(['user-attachments', 'orgs', 'apps', 'marketplace'])
1113
const OWNER = 'linuxfoundation'
1214
const REPO = 'insights'
13-
const CATEGORY_SLUG = 'project-onboardings'
1415

1516
interface GraphQLResponse<T> {
1617
data?: T
1718
errors?: Array<{ message: string }>
1819
}
1920

21+
interface DiscussionNode {
22+
number: number
23+
body: string
24+
closed: boolean
25+
}
26+
27+
interface DiscussionsPage {
28+
pageInfo: { hasNextPage: boolean; endCursor: string | null }
29+
nodes: DiscussionNode[]
30+
}
31+
32+
interface DiscussionsData {
33+
repository: {
34+
discussions: DiscussionsPage
35+
}
36+
}
37+
2038
async function graphqlRequest<T>(query: string, variables: Record<string, unknown>): Promise<T> {
2139
const raw = process.env.CROWD_GITHUB_PERSONAL_ACCESS_TOKENS
2240
if (!raw) {
@@ -75,17 +93,16 @@ async function graphqlRequest<T>(query: string, variables: Record<string, unknow
7593
})
7694
}
7795

78-
const GITHUB_NON_REPO_OWNERS = new Set(['user-attachments', 'orgs', 'apps', 'marketplace'])
7996

8097
// Extracts github.com/{owner}/{repo} URLs from markdown text, normalised to the repo root.
8198
function extractRepoUrls(text: string): string[] {
8299
const urls = new Set<string>()
83100
const regex = /https?:\/\/github\.com\/([a-zA-Z0-9_.-]+)\/([a-zA-Z0-9_.-]+)/gi
84101
let match: RegExpExecArray | null
85102
while ((match = regex.exec(text)) !== null) {
86-
const owner = match[1]
87-
const repo = match[2].replace(/\.git$/, '')
88-
if (owner && repo && !GITHUB_NON_REPO_OWNERS.has(owner.toLowerCase())) {
103+
const owner = match[1].toLowerCase()
104+
const repo = match[2].replace(/\.git$/, '').replace(/[.,;:!?]+$/, '').toLowerCase()
105+
if (owner && repo && !GITHUB_NON_REPO_OWNERS.has(owner)) {
89106
urls.add(`https://github.com/${owner}/${repo}`)
90107
}
91108
}
@@ -129,16 +146,6 @@ async function getDiscussionCategoryId(): Promise<string> {
129146
return category.id
130147
}
131148

132-
interface DiscussionNode {
133-
number: number
134-
body: string
135-
closed: boolean
136-
}
137-
138-
interface DiscussionsPage {
139-
pageInfo: { hasNextPage: boolean; endCursor: string | null }
140-
nodes: DiscussionNode[]
141-
}
142149

143150
async function fetchDiscussionsPage(
144151
categoryId: string,
@@ -162,12 +169,6 @@ async function fetchDiscussionsPage(
162169
}
163170
`
164171

165-
interface DiscussionsData {
166-
repository: {
167-
discussions: DiscussionsPage
168-
}
169-
}
170-
171172
const data = await graphqlRequest<DiscussionsData>(query, { categoryId, cursor })
172173
return data.repository.discussions
173174
}
@@ -186,7 +187,6 @@ async function fetchAllDiscussionRepoUrls(): Promise<string[]> {
186187
const page = await fetchDiscussionsPage(categoryId, cursor)
187188

188189
for (const discussion of page.nodes) {
189-
if (discussion.closed) continue
190190
for (const url of extractRepoUrls(discussion.body)) {
191191
allUrls.add(url)
192192
}

services/apps/automatic_projects_discovery_worker/src/sources/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export interface IDiscoverySourceRow {
2222
projectSlug: string
2323
repoName: string
2424
repoUrl: string
25-
action?: string
25+
action?: 'auto' | 'evaluate' | 'onboard' | 'unsure'
2626
lfCriticalityScore?: number
2727
}

services/libs/data-access-layer/src/project-catalog/types.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ type ProjectCatalogWritable = Pick<
1818
'projectSlug' | 'repoName' | 'repoUrl' | 'source' | 'action' | 'lfCriticalityScore'
1919
>
2020

21-
export type IDbProjectCatalogCreate = Omit<ProjectCatalogWritable, 'lfCriticalityScore'> & {
21+
export type IDbProjectCatalogCreate = Omit<
22+
ProjectCatalogWritable,
23+
'source' | 'action' | 'lfCriticalityScore'
24+
> & {
25+
source?: string | null
26+
action?: string
2227
lfCriticalityScore?: number
2328
}
2429

2530
export type IDbProjectCatalogUpdate = Partial<ProjectCatalogWritable> & {
26-
syncedAt?: string
27-
evaluatedAt?: string
28-
onboardedAt?: string
31+
syncedAt?: string | null
32+
evaluatedAt?: string | null
33+
onboardedAt?: string | null
2934
}

0 commit comments

Comments
 (0)