Skip to content

Commit

Permalink
Merge branch 'main' into docs/#180
Browse files Browse the repository at this point in the history
  • Loading branch information
D0ri123 authored Oct 14, 2024
2 parents 2e6205a + ce47f83 commit 981af35
Show file tree
Hide file tree
Showing 30 changed files with 1,083 additions and 84 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
```
npm install
npm run dev
npm run lint
```
101 changes: 68 additions & 33 deletions components/contributeInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import { useEffect, useState, useRef } from 'react';
import { Octokit } from 'octokit';
import { initializeApp } from 'firebase/app';
import { getFirestore, doc, getDoc } from 'firebase/firestore';
import { useTheme } from 'nextra-theme-docs';
import Table from './common/table';

const firebaseConfig = {
apiKey: 'AIzaSyCMC07HfFRIFUVMA7eULAsmTvoC7Frpna8',
authDomain: 'my-oss-pr.firebaseapp.com',
projectId: 'my-oss-pr',
storageBucket: 'my-oss-pr.appspot.com',
messagingSenderId: '6268125850',
appId: '1:6268125850:web:d84b95103cbd1e81a21523',
measurementId: 'G-RLP5Y94VKY',
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

async function fetchToken() {
const docRef = doc(db, 'oss', 'info');
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
return docSnap.data().token;
}
console.error('No token found in Firestore');
return null;
}

const gitProfileBuilder = userInfo => (
<div className="flex items-center">
<div className="w-7 h-7 flex-shrink-0 mr-2 sm:mr-3">
Expand Down Expand Up @@ -57,38 +82,12 @@ const gitIssueTypeBuilder = (issueTypeInfo, cloasedAt) => {
return issueType;
};

const gitIssueBuilder = async (githubId, owner, repo) => {
const octokit = new Octokit({});
const response = await octokit.request('GET /repos/{owner}/{repo}/issues', {
owner,
repo,
creator: githubId,
state: 'all',
headers: { 'X-GitHub-Api-Version': '2022-11-28' },
});

const issueObj = response.data;

if (issueObj.length === 0) {
return [
{
GitHub: {
data: gitProfileBuilder({ login: githubId, avatar_url: `https://github.com/${githubId}.png`, html_url: `https://github.com/${githubId}` }),
searchLabel: githubId,
},
Type: {
data: 'None',
searchLabel: 'None',
},
Summary: {
data: 'No contributions or issues',
searchLabel: null,
},
},
];
const parseIssues = issues => {
if (issues.length === 0) {
return [];
}

return issueObj.map(issue => ({
return issues.map(issue => ({
GitHub: {
data: gitProfileBuilder(issue.user),
searchLabel: issue.user.login,
Expand All @@ -104,6 +103,38 @@ const gitIssueBuilder = async (githubId, owner, repo) => {
}));
};

const gitIssueBuilder = async (githubId, owner, repo) => {
const token = await fetchToken();
const octokitAuth = new Octokit({ auth: token });
const octokitNoAuth = new Octokit();

try {
const response = await octokitAuth.request('GET /repos/{owner}/{repo}/issues', {
owner,
repo,
creator: githubId,
state: 'all',
headers: { 'X-GitHub-Api-Version': '2022-11-28' },
});
return parseIssues(response.data);
} catch (error) {
// 인증된 요청 실패 시 비인증 요청 시도
console.error('Auth request is failed. Do non-auth reaquest instead.');
try {
const response = await octokitNoAuth.request('GET /repos/{owner}/{repo}/issues', {
owner,
repo,
creator: githubId,
state: 'all',
headers: { 'X-GitHub-Api-Version': '2022-11-28' },
});
return parseIssues(response.data);
} catch (unauthError) {
return [];
}
}
};

const contributeInfoBuilder = async (contributers, owner, repo) => {
const promise = contributers.map(async contributer => await gitIssueBuilder(contributer, owner, repo));
const contributeInfo = await Promise.all(promise);
Expand All @@ -128,19 +159,23 @@ const ContributeInfo = ({ contributers = [], owner = 'argoproj', repo = 'argo-wo
contributeInfoBuilder(contributersRef, owner, repo).then(data => setIssueList(data));
}, [contributersRef, owner, repo, contributeInfoBuilder, setIssueList, theme]);

const prCnt = issueList.filter(issue => issue.Type.searchLabel === 'PR').length;
const issueCnt = issueList.filter(issue => issue.Type.searchLabel === 'ISSUE').length;
const totalCnt = prCnt + issueCnt;

const contributeSummary = (
<div className="grid grid-cols-3 gap-5 mt-2 text-center text-gray-600 text-sm">
<div className="grid grid-cols-3">
<div className="col-span-2 bg-orange-200 p-3 rounded-l-md font-semibold">TOTAL COUNT</div>
<div className="bg-gray-100 p-3 rounded-r-md font-semibold text-orange-400">{issueList.length}</div>
<div className="bg-gray-100 p-3 rounded-r-md font-semibold text-orange-400">{totalCnt}</div>
</div>
<div className="grid grid-cols-3">
<div className="col-span-2 bg-blue-100 p-3 rounded-l-md font-medium">PR COUNT</div>
<div className="bg-gray-100 p-3 rounded-r-md font-medium text-blue-600">{issueList.filter(issue => issue.Type.searchLabel === 'PR').length}</div>
<div className="bg-gray-100 p-3 rounded-r-md font-medium text-blue-600">{prCnt}</div>
</div>
<div className="grid grid-cols-3">
<div className="col-span-2 bg-gray-200 p-3 rounded-l-md font-medium">ISSUE COUNT</div>
<div className="bg-gray-100 p-3 rounded-r-md font-medium">{issueList.filter(issue => issue.Type.searchLabel === 'ISSUE').length}</div>
<div className="bg-gray-100 p-3 rounded-r-md font-medium">{issueCnt}</div>
</div>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const withNextra = require('nextra')({

module.exports = {
...withNextra(),
env: {
OCTOKIT_TOKEN: process.env.OCTOKIT_TOKEN
},
images: {
unoptimized: true, // static page로 배포하려면 반드시 필요
// staticImage: true,
Expand Down
Loading

0 comments on commit 981af35

Please sign in to comment.