A JavaScript API to fetch data from DeepSource.
Start by importing the library:
import DeepSource from "deepsource-node";
// or require("deepsource-node")
Then use your Personal Access Token to create a driver.
const deepsource = new DeepSourceAPI("<your personal access token>");
Now, you can use fetch data from the API using the driver:
const repo = await deepsource.getRepo("repo-name", "user-name");
console.log(repo);
repo
will look like this:
{
defaultBranch: 'master',
dsn: 'https://[email protected]',
isPrivate: false,
runIds: [Array]
}
To fetch all active issues in the repo:
// All issues raised by DeepSource:
const allIssues = await deepsource.getAllIssuesInRepo("repo-name", "user-name");
console.log(allIssues);
Output:
[{
issue: {
code: 'JS-D023',
title: 'Unsafe `child_process` non-literal',
category: 'SECURITY',
tags: [Array]
},
path: 'index.js',
beginColumn: 1,
beginLine: 35,
endColumn: 20,
endLine: 35
},
... 100 more items
]
Or, you can make an arbitrary GraphQL query by following the schema in the docs.
For such requests, the response will be a Record<string, any>
, instead of having proper type definitions.
deepsource.fetch(`query {
run(runUid:"") {
checks {
totalCount
edges {
node {
analyzer { name }
}
}
}
}
}`);