Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions jira/jira-issues-to-dust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(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(
", "
)}`
);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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(""))
Copy link
Contributor Author

@Djiit Djiit Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some of our tickets had objects like type: rule in it, without any content.

.join("\n") || ""
);
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions jira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "ISC",
"dependencies": {
"axios": "^1.7.7",
"bottleneck" :"^2.9.15",
"dotenv": "^16.0.3",
"p-limit": "^3.1.0"
},
Expand Down