Skip to content

Commit

Permalink
Merge pull request #549 from vishnoianil/dco-error
Browse files Browse the repository at this point in the history
Fixes DCO signoff issue
  • Loading branch information
Gregory-Pereira authored Feb 4, 2025
2 parents 7072405 + 1f65899 commit 43c7d09
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/app/edit-submission/knowledge/[id]/page.tsx
// src/app/components/contribute/EditKnowledge/github/EditKnowledge.tsx
'use client';

import * as React from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/app/edit-submission/knowledge/native/[id]/EditKnowledge.tsx
// src/app/components/contribute/EditKnowledge/native/EditKnowledge.tsx
'use client';

import * as React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Contribute/EditSkill/github/EditSkill.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/app/edit-submission/skill/[id]/EditSkillClientComponent.tsx
// src/app/components/contribute/EditSkill/github/EditSkill.tsx
'use client';

import * as React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Contribute/EditSkill/native/EditSkill.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/app/edit-submission/skill/native/[id]/EditSkill.tsx
// src/app/components/contribute/EditSkill/native/EditSkill.tsx
'use client';

import * as React from 'react';
Expand Down
22 changes: 8 additions & 14 deletions src/components/Contribute/Knowledge/Github/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use client';
import React, { useEffect, useMemo, useState } from 'react';
import '../knowledge.css';
import { getGitHubUsername } from '@/utils/github';
import { getGitHubUserInfo } from '@/utils/github';
import { useSession } from 'next-auth/react';
import AuthorInformation from '@/components/Contribute/AuthorInformation';
import { FormType } from '@/components/Contribute/AuthorInformation';
Expand Down Expand Up @@ -153,15 +153,8 @@ export const KnowledgeFormGithub: React.FunctionComponent<KnowledgeFormProps> =
getEnvVariables();
}, []);

useEffect(() => {
if (session?.user?.name && session?.user?.email) {
setName(session?.user?.name);
setEmail(session?.user?.email);
}
}, [session?.user]);

useMemo(() => {
const fetchUsername = async () => {
const fetchUserInfo = async () => {
if (session?.accessToken) {
try {
const headers = {
Expand All @@ -171,15 +164,17 @@ export const KnowledgeFormGithub: React.FunctionComponent<KnowledgeFormProps> =
'X-GitHub-Api-Version': '2022-11-28'
};

const fetchedUsername = await getGitHubUsername(headers);
setGithubUsername(fetchedUsername);
const fetchedUserInfo = await getGitHubUserInfo(headers);
setGithubUsername(fetchedUserInfo.login);
setName(fetchedUserInfo.name);
setEmail(fetchedUserInfo.email);
} catch (error) {
console.error('Failed to fetch GitHub username:', error);
console.error('Failed to fetch GitHub user info:', error);
}
}
};

fetchUsername();
fetchUserInfo();
}, [session?.accessToken]);

useEffect(() => {
Expand Down Expand Up @@ -523,7 +518,6 @@ export const KnowledgeFormGithub: React.FunctionComponent<KnowledgeFormProps> =
};

const onYamlUploadKnowledgeFillForm = (data: KnowledgeYamlData): void => {
setName(data.created_by ?? '');
setDocumentOutline(data.document_outline ?? '');
setSubmissionSummary(data.document_outline ?? '');
setDomain(data.domain ?? '');
Expand Down
22 changes: 8 additions & 14 deletions src/components/Contribute/Skill/Github/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use client';
import React, { useEffect, useState } from 'react';
import '../skills.css';
import { getGitHubUsername } from '../../../../utils/github';
import { getGitHubUserInfo } from '../../../../utils/github';
import { useSession } from 'next-auth/react';
import FilePathInformation from '../FilePathInformation/FilePathInformation';
import AttributionInformation from '../AttributionInformation/AttributionInformation';
Expand Down Expand Up @@ -122,14 +122,7 @@ export const SkillFormGithub: React.FunctionComponent<SkillFormProps> = ({ skill
}, []);

useEffect(() => {
if (session?.user?.name && session?.user?.email) {
setName(session?.user?.name);
setEmail(session?.user?.email);
}
}, [session?.user]);

useEffect(() => {
const fetchUsername = async () => {
const fetchUserInfo = async () => {
if (session?.accessToken) {
try {
const headers = {
Expand All @@ -139,15 +132,17 @@ export const SkillFormGithub: React.FunctionComponent<SkillFormProps> = ({ skill
'X-GitHub-Api-Version': '2022-11-28'
};

const fetchedUsername = await getGitHubUsername(headers);
setGithubUsername(fetchedUsername);
const fetchedUserInfo = await getGitHubUserInfo(headers);
setGithubUsername(fetchedUserInfo.login);
setName(fetchedUserInfo.name);
setEmail(fetchedUserInfo.email);
} catch (error) {
console.error('Failed to fetch GitHub username:', error);
console.error('Failed to fetch GitHub user info:', error);
}
}
};

fetchUsername();
fetchUserInfo();
}, [session?.accessToken]);

useEffect(() => {
Expand Down Expand Up @@ -331,7 +326,6 @@ export const SkillFormGithub: React.FunctionComponent<SkillFormProps> = ({ skill
};

const onYamlUploadSkillsFillForm = (data: SkillYamlData): void => {
setName(data.created_by ?? '');
setDocumentOutline(data.task_description ?? '');
setSeedExamples(yamlSeedExampleToFormSeedExample(data.seed_examples));
};
Expand Down
44 changes: 44 additions & 0 deletions src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import axios from 'axios';
import { PullRequestUpdateData } from '@/types';
import { BASE_BRANCH, FORK_CLONE_CHECK_RETRY_COUNT, FORK_CLONE_CHECK_RETRY_TIMEOUT, GITHUB_API_URL } from '@/types/const';

type GithubUserInfo = {
login: string;
name: string;
email: string;
};

export async function fetchPullRequests(token: string) {
try {
console.log('Refreshing PR Listing');
Expand Down Expand Up @@ -297,6 +303,28 @@ export const amendCommit = async (
throw error;
}
};
export async function getGitHubUserInfo(headers: HeadersInit): Promise<GithubUserInfo> {
const response = await fetch(`${GITHUB_API_URL}/user`, {
headers
});

if (!response.ok) {
const errorText = await response.text();
console.error('Failed to fetch GitHub user info:', response.status, errorText);
throw new Error('Failed to fetch GitHub user info');
}

const data = await response.json();

const userInfo: GithubUserInfo = {
name: data.name,
login: data.login,
email: ''
};

userInfo.email = await getGitHubUserPrimaryEmail(headers);
return userInfo;
}

export async function getGitHubUsername(headers: HeadersInit): Promise<string> {
const response = await fetch(`${GITHUB_API_URL}/user`, {
Expand All @@ -313,6 +341,22 @@ export async function getGitHubUsername(headers: HeadersInit): Promise<string> {
return data.login;
}

export async function getGitHubUserPrimaryEmail(headers: HeadersInit): Promise<string> {
const response = await fetch(`${GITHUB_API_URL}/user/public_emails`, {
headers
});

if (!response.ok) {
const errorText = await response.text();
console.error('Failed to fetch GitHub email address:', response.status, errorText);
throw new Error('Failed to fetch GitHub email address');
}

const data = await response.json();
const emailInfo = data.find((emailObj: { primary: boolean }) => emailObj.primary === true);
return emailInfo.email;
}

export async function createFork(headers: HeadersInit, upstreamRepoOwner: string, upstreamRepoName: string, username: string) {
const response = await fetch(`${GITHUB_API_URL}/repos/${upstreamRepoOwner}/${upstreamRepoName}/forks`, {
method: 'POST',
Expand Down

0 comments on commit 43c7d09

Please sign in to comment.