feat: add Gitea support with new widgets and API integration
This commit is contained in:
77
src/utils/giteaApi.ts
Normal file
77
src/utils/giteaApi.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import axios from 'axios';
|
||||
|
||||
// Gitea API configuration
|
||||
|
||||
const createGiteaApi = (baseUrl, token = null) => {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
if (token) {
|
||||
headers.Authorization = `token ${token}`;
|
||||
}
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: `${baseUrl}/api/v1`,
|
||||
headers,
|
||||
});
|
||||
|
||||
return {
|
||||
// Fetch commits for a repository
|
||||
fetchCommits: async (owner, repo, limit = 10, branch = 'main') => {
|
||||
try {
|
||||
const response = await api.get(
|
||||
`/repos/${owner}/${repo}/commits`,
|
||||
{
|
||||
params: {
|
||||
limit,
|
||||
page: 1,
|
||||
sha: branch, // Optional branch parameter
|
||||
}
|
||||
}
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching Gitea commits:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Fetch user repositories
|
||||
fetchUserRepos: async (username) => {
|
||||
try {
|
||||
const response = await api.get(`/users/${username}/repos`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching user repos:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Fetch repository information
|
||||
fetchRepoInfo: async (owner, repo) => {
|
||||
try {
|
||||
const response = await api.get(`/repos/${owner}/${repo}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching repo info:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Search repositories
|
||||
searchRepos: async (query) => {
|
||||
try {
|
||||
const response = await api.get('/repos/search', {
|
||||
params: { q: query, limit: 10 }
|
||||
});
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.error('Error searching repos:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default createGiteaApi;
|
||||
Reference in New Issue
Block a user