-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(jira): support vault id #41
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,28 @@ const JIRA_API_TOKEN = process.env.JIRA_API_TOKEN; | |
const JIRA_QUERY = process.env.JIRA_QUERY || DEFAULT_JIRA_QUERY; | ||
const DUST_API_KEY = process.env.DUST_API_KEY; | ||
const DUST_WORKSPACE_ID = process.env.DUST_WORKSPACE_ID; | ||
const DUST_VAULT_ID = process.env.DUST_VAULT_ID; | ||
const DUST_DATASOURCE_ID = process.env.DUST_DATASOURCE_ID; | ||
|
||
const requiredEnvVars = [ | ||
'JIRA_SUBDOMAIN', | ||
'JIRA_EMAIL', | ||
'JIRA_API_TOKEN', | ||
'DUST_API_KEY', | ||
'DUST_WORKSPACE_ID', | ||
'DUST_DATASOURCE_ID' | ||
"JIRA_SUBDOMAIN", | ||
"JIRA_EMAIL", | ||
"JIRA_API_TOKEN", | ||
"DUST_API_KEY", | ||
"DUST_WORKSPACE_ID", | ||
"DUST_VAULT_ID", | ||
"DUST_DATASOURCE_ID", | ||
]; | ||
|
||
const missingEnvVars = requiredEnvVars.filter(varName => !process.env[varName]); | ||
const missingEnvVars = requiredEnvVars.filter( | ||
Comment on lines
13
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please ensure consistent use of single quotes for strings to adhere to coding standards. Change instances of double quotes to single quotes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line formatting seems off. The lambda function should be on the same line as the filter method for better readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please ensure consistent use of single quotes for strings to adhere to coding standards. Change instances of double quotes to single quotes. |
||
(varName) => !process.env[varName] | ||
); | ||
|
||
if (missingEnvVars.length > 0) { | ||
throw new Error( | ||
`Please provide values for the following environment variables: ${missingEnvVars.join(', ')}` | ||
`Please provide values for the following environment variables: ${missingEnvVars.join( | ||
", " | ||
)}` | ||
); | ||
} | ||
|
||
|
@@ -157,7 +163,9 @@ async function getIssuesUpdatedLast24Hours(): Promise<JiraIssue[]> { | |
const maxResults = 50; | ||
let total = 0; | ||
|
||
const makeRequest = async (retryCount = 0): Promise<AxiosResponse<JiraSearchResponse>> => { | ||
const makeRequest = async ( | ||
retryCount = 0 | ||
): Promise<AxiosResponse<JiraSearchResponse>> => { | ||
try { | ||
return await jiraApi.post("/search", { | ||
jql: JIRA_QUERY, | ||
|
@@ -195,9 +203,14 @@ async function getIssuesUpdatedLast24Hours(): Promise<JiraIssue[]> { | |
} catch (error) { | ||
if (axios.isAxiosError(error) && error.response) { | ||
if (error.response.status === 429 && retryCount < 3) { | ||
const retryAfter = parseInt(error.response.headers['retry-after'] || '60', 10); | ||
const retryAfter = parseInt( | ||
error.response.headers["retry-after"] || "60", | ||
10 | ||
); | ||
console.log(`Rate limited. Retrying after ${retryAfter} seconds...`); | ||
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000)); | ||
await new Promise((resolve) => | ||
setTimeout(resolve, retryAfter * 1000) | ||
); | ||
return makeRequest(retryCount + 1); | ||
} | ||
} | ||
|
@@ -235,7 +248,7 @@ function formatDescription( | |
): string { | ||
return ( | ||
description?.content | ||
.map((c) => c.content.map((cc) => cc.text).join("")) | ||
.map((c) => c.content?.map((cc) => cc.text).join("")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like some of our tickets had objects like |
||
.join("\n") || "" | ||
); | ||
} | ||
|
@@ -317,7 +330,7 @@ ${formatComments(issue.fields.comment.comments)} | |
|
||
try { | ||
await dustApi.post( | ||
`/w/${DUST_WORKSPACE_ID}/data_sources/${DUST_DATASOURCE_ID}/documents/${documentId}`, | ||
`/w/${DUST_WORKSPACE_ID}/vaults/${DUST_VAULT_ID}/data_sources/${DUST_DATASOURCE_ID}/documents/${documentId}`, | ||
{ | ||
text: content, | ||
} | ||
|
@@ -341,13 +354,12 @@ async function main() { | |
|
||
const limiter = new Bottleneck({ | ||
maxConcurrent: DUST_RATE_LIMIT, | ||
minTime: 60 * 1000 / DUST_RATE_LIMIT, | ||
minTime: (60 * 1000) / DUST_RATE_LIMIT, | ||
}); | ||
|
||
const tasks = recentIssues.map((issue) => | ||
limiter.schedule(() => upsertToDustDatasource(issue)) | ||
); | ||
|
||
await Promise.all(tasks); | ||
console.log("All issues processed successfully."); | ||
} catch (error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line formatting seems off. The lambda function should be on the same line as the filter method for better readability.