-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub code support: Move issues/discussions to separate parents in g…
…ithub connectors (#3032) * Add issues/discussions parents at aggregation and permission retrieval * make github nested, remove default prefix for channels * re-add # to channel title for slack connector permissions * dry * add migration to add parents for github issues and discussions * lint
- Loading branch information
Showing
9 changed files
with
227 additions
and
46 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
connectors/migrations/20240102_github_add_issues_discussions_parents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { | ||
getDiscussionDocumentId, | ||
getIssueDocumentId, | ||
} from "@connectors/connectors/github/temporal/activities"; | ||
import { updateDocumentParentsField } from "@connectors/lib/data_sources"; | ||
import { Connector } from "@connectors/lib/models"; | ||
import { GithubDiscussion, GithubIssue } from "@connectors/lib/models/github"; | ||
|
||
const { LIVE = null } = process.env; | ||
|
||
async function main() { | ||
const connectors = await Connector.findAll({ | ||
where: { | ||
type: "github", | ||
}, | ||
}); | ||
|
||
for (const connector of connectors) { | ||
console.log(`>> Updating connector: ${connector.id}`); | ||
await updateParents(connector); | ||
} | ||
} | ||
|
||
const CHUNK_SIZE = 32; | ||
|
||
async function updateParents(connector: Connector) { | ||
const discussions = await GithubDiscussion.findAll({ | ||
where: { | ||
connectorId: connector.id, | ||
}, | ||
}); | ||
|
||
const discussionChunks = []; | ||
for (let i = 0; i < discussions.length; i += CHUNK_SIZE) { | ||
discussionChunks.push(discussions.slice(i, i + CHUNK_SIZE)); | ||
} | ||
|
||
for (const chunk of discussionChunks) { | ||
await Promise.all( | ||
chunk.map(async (d) => { | ||
const documentId = getDiscussionDocumentId( | ||
d.repoId, | ||
d.discussionNumber | ||
); | ||
const parents = [documentId, `${d.repoId}-discussions`, d.repoId]; | ||
if (LIVE) { | ||
await updateDocumentParentsField({ | ||
dataSourceConfig: connector, | ||
documentId, | ||
parents, | ||
}); | ||
console.log(`Updated discussion ${documentId} with: ${parents}`); | ||
} else { | ||
console.log(`Would update ${documentId} with: ${parents}`); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
const issues = await GithubIssue.findAll({ | ||
where: { | ||
connectorId: connector.id, | ||
}, | ||
}); | ||
|
||
const issueChunks = []; | ||
for (let i = 0; i < issues.length; i += CHUNK_SIZE) { | ||
issueChunks.push(issues.slice(i, i + CHUNK_SIZE)); | ||
} | ||
|
||
for (const chunk of issueChunks) { | ||
await Promise.all( | ||
chunk.map(async (i) => { | ||
const documentId = getIssueDocumentId(i.repoId, i.issueNumber); | ||
const parents = [documentId, `${i.repoId}-issues`, i.repoId]; | ||
if (LIVE) { | ||
await updateDocumentParentsField({ | ||
dataSourceConfig: connector, | ||
documentId, | ||
parents, | ||
}); | ||
console.log(`Updated issue ${documentId} with: ${parents}`); | ||
} else { | ||
console.log(`Would update ${documentId} with: ${parents}`); | ||
} | ||
}) | ||
); | ||
} | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log("Done"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters