Skip to content
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
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ To start contributing, follow these steps:

4. **Set Up GitHub API Token:**

- Visit GitHub Developer Settings to generate **three** personal access tokens.
- Visit GitHub Developer Settings to generate **three fine-grained** personal access tokens.
- Make Sure to Add some useful permissions to access smoothly and Seamless interaction with the api.
- Permissions: [Actions, Commit statues, Contents, Issues, Merge queues, Metadata, Pages, Pull request, and any other Permissions of your choice.]
- Create a `.env.local` file in the project root and add your token as follows:

```sh
Expand Down
24 changes: 24 additions & 0 deletions pages/failed-lang/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import IssuesCard from "@/components/IssuesCard";

// This page is used when getStaticProps or getStaticPath failed to handle the errors founds in fetching issues.
// It displays a message indicating redirect to home or github dashboard and suggests trying again.
// Default issue object below

var issueObj = {
issueId: 0,
issueNumber: 0,
issueUrl: '/',
issueTitle: 'Something went wrong in getting your relevant programming language. please try again',
repoTitle: 'dashboard',
createdAt: 'Not_working4',
repo_forks: 0,
repo_stars: 0,
language: 'Not_working5',
repo_title: '/'
}

export default function Failed_lang() {
return (
<IssuesCard issue={issueObj} />
);
}
97 changes: 31 additions & 66 deletions pages/search/[lang].js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { FaSort } from "react-icons/fa";
import error_404 from "../../public/404.svg";
import Link from "next/link";

// Importing Test file start here
import { loadIssues } from "./testing-file";
// Importing Test file ends here

import { langs } from "@/helper/Languages";
import SeoTags from "@/components/SeoTags";
import moment from "moment";
Expand Down Expand Up @@ -230,80 +234,31 @@ export default function Search({ allIssues, lang }) {
);
}

async function loadRepo(issueItems) {
var repoObj = {};
for (const issue of issueItems) {
const repores = await fetch(issue.repository_url, {
headers: {
Authorization: "token " + process.env.NEXT_PUBLIC_TOKEN_SECOND,
Accept: "application/vnd.github.v3+json",
},
});
const repojson = await repores.json();

repoObj[issue.id] = {
full_name: repojson.full_name,
stargazers_count: repojson.stargazers_count,
forks_count: repojson.forks_count,
};
}

return repoObj;
}

async function loadIssues(url, query_lang) {
const issues_res = await fetch(url, {
headers: {
Authorization: "token " + process.env.NEXT_PUBLIC_TOKEN_FIRST,
Accept: "application/vnd.github.v3+json",
},
});

const issues_json = await issues_res.json();
const issueItems = issues_json.items;

var allIssues = [];

var repo_res = await loadRepo(issueItems);
var mask = "";
if (url.includes("label")) {
mask = "tag";
} else {
mask = "language";
}
issueItems.forEach((issue) => {
var lang = query_lang;

var issueObj = {
issueId: issue.id,
issueNumber: issue.number,
issueUrl: issue.html_url,
issueTitle: issue.title,
repoTitle: repo_res[issue.id].full_name,
createdAt: issue.created_at,
repo_forks: repo_res[issue.id].forks_count,
repo_stars: repo_res[issue.id].stargazers_count,

[mask]: query_lang,
};

if (issueObj.repo_forks > 0 && issueObj.repo_stars > 0) {
allIssues.push(issueObj);
}
});

// setIssues(allIssues);
return allIssues;
}
export async function getStaticPaths() {
try {

const paths = priority_langs.map((lang) => ({
params: { lang: lang.query },
}));

return { paths, fallback: true };

} catch {
// Redirect to failed-lang page if there is an error and getStaticProps fail to handle the error.
return {
redirect: {
destination: "/failed-lang",
permanent: false,
}
}
}
}

export async function getStaticProps({ params }) {

try {

let url = "";
tags.forEach((tag) => {
if (params.lang == "go") {
Expand All @@ -324,7 +279,7 @@ export async function getStaticProps({ params }) {
});
}

let lang_issues = "";
let lang_issues = [];

if (url.length > 0) {
lang_issues = await loadIssues(url, params.lang);
Expand All @@ -337,4 +292,14 @@ export async function getStaticProps({ params }) {
},
revalidate: 600,
};
}

} catch {
// Redirect to failed-lang page if there is an error and getStaticProps fail to handle the error.
return {
redirect: {
destination: "/failed-lang",
permanent: false,
}
}
}
}
90 changes: 90 additions & 0 deletions pages/search/testing-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const errorActive = [];

async function loadRepo(issueItems) {
try {
var repoObj = {};
for (const issue of issueItems) {
const repores = await fetch(issue.repository_url, {
headers: {
Authorization: "token " + process.env.NEXT_PUBLIC_TOKEN_SECOND,
Accept: "application/vnd.github.v3+json",
},
});
const repojson = await repores.json();

repoObj[issue.id] = {
full_name: repojson.full_name,
stargazers_count: repojson.stargazers_count,
forks_count: repojson.forks_count,
};
}

return repoObj;

} catch (error) {
console.error("Error fetching Data:", error);
errorActive.push(true);
return null; // return null and letting getStaticProps handle the error
}
}

export async function loadIssues(url, query_lang) {
try {
const issues_res = await fetch(url, {
headers: {
Authorization: "token " + process.env.NEXT_PUBLIC_TOKEN_FIRST,
Accept: "application/vnd.github.v3+json",
},
});

const issues_json = await issues_res.json();
const issueItems = issues_json.items;

var allIssues = [];

var repo_res = await loadRepo(issueItems);
var mask = "";
if (url.includes("label")) {
mask = "tag";
} else {
mask = "language";
}
issueItems.forEach((issue) => {
var lang = query_lang;

var issueObj = {
issueId: issue.id,
issueNumber: issue.number,
issueUrl: issue.html_url,
issueTitle: issue.title,
repoTitle: repo_res[issue.id].full_name,
createdAt: issue.created_at,
repo_forks: repo_res[issue.id].forks_count,
repo_stars: repo_res[issue.id].stargazers_count,

[mask]: query_lang,
};

if (issueObj.repo_forks > 0 && issueObj.repo_stars > 0) {
allIssues.push(issueObj);
}
});

// setIssues(allIssues);
return allIssues;

} catch (error) {
console.error("Error Getting Issues:", error);
errorActive.push(true);
return null; // return null and letting getStaticProps handle the error
}

}

export default function TestingError() {
if(errorActive.length > 0) {
return true;
} else {
return false;
}
}