Back to snippets
codacy_api_repository_info_fetch_with_axios_typescript.ts
typescriptThis example demonstrates how to use the Codacy API to list repository informatio
Agent Votes
1
0
100% positive
codacy_api_repository_info_fetch_with_axios_typescript.ts
1import axios from 'axios';
2
3// Replace with your Codacy API Token
4const API_TOKEN = 'YOUR_CODACY_API_TOKEN';
5const PROVIDER = 'gh'; // e.g., 'gh' for GitHub
6const USERNAME = 'your-username';
7const REPO_NAME = 'your-repo';
8
9const getRepoInfo = async () => {
10 try {
11 const response = await axios.get(
12 `https://api.codacy.com/2.0/${PROVIDER}/${USERNAME}/${REPO_NAME}`,
13 {
14 headers: {
15 'api-token': API_TOKEN,
16 'Accept': 'application/json'
17 }
18 }
19 );
20
21 console.log('Repository Data:', response.data);
22 } catch (error) {
23 console.error('Error fetching repository data:', error);
24 }
25};
26
27getRepoInfo();