Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add the ability for a user to amend a commit #24

Merged
merged 5 commits into from
Jun 26, 2024
Merged
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: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ IL_GRANITE_MODEL_NAME=<GRANITE_MODEL_NAME>
IL_MERLINITE_API=<MERLINITE_HOST>
IL_MERLINITE_MODEL_NAME=<MERLINITE_MODEL_NAME>
GITHUB_TOKEN=<TOKEN FOR OAUTH INSTRUCTLAB MEMBER LOOKUP>
TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
TAXONOMY_REPO=<REPO_NAME>
TAXONOMY_DOCUMENTS_REPO=github.com/<USER_ID>/<REPO_NAME>
NEXT_PUBLIC_TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
NEXT_PUBLIC_TAXONOMY_REPO=<REPO_NAME>
18 changes: 10 additions & 8 deletions src/app/api/pr/knowledge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { NextResponse } from 'next/server';
import { getToken } from 'next-auth/jwt';
import { NextRequest } from 'next/server';
import yaml from 'js-yaml';
import { SchemaVersion } from '@/types';

const GITHUB_API_URL = 'https://api.github.com';
const UPSTREAM_REPO_OWNER = process.env.TAXONOMY_REPO_OWNER!;
const UPSTREAM_REPO_NAME = process.env.TAXONOMY_REPO!;
const UPSTREAM_REPO_OWNER = process.env.NEXT_PUBLIC_TAXONOMY_REPO_OWNER!;
const UPSTREAM_REPO_NAME = process.env.NEXT_PUBLIC_TAXONOMY_REPO!;
const BASE_BRANCH = 'main';

export async function POST(req: NextRequest) {
Expand All @@ -32,7 +33,7 @@ export async function POST(req: NextRequest) {
name,
email,
task_description,
task_details,
submission_summary,
domain,
repo,
commit,
Expand All @@ -54,7 +55,7 @@ export async function POST(req: NextRequest) {
const forkExists = await checkUserForkExists(headers, githubUsername);
if (!forkExists) {
await createFork(headers);
// Add a delay to ensure the fork operation completes to avoid a race condition when retrieving the bas SHA
// Add a delay to ensure the fork operation completes to avoid a race condition when retrieving the base SHA
// This only occurs if this is the first time submitting and the fork isn't present.
// TODO change to a retry
console.log('Pause 5s for the forking operation to complete');
Expand All @@ -78,6 +79,7 @@ export async function POST(req: NextRequest) {

const yamlData = {
created_by: githubUsername,
version: SchemaVersion,
domain: domain,
task_description: task_description,
seed_examples: questions.map((question: string, index: number) => {
Expand Down Expand Up @@ -117,11 +119,11 @@ Creator names: ${creators}
{ path: newAttributionFilePath, content: attributionContent }
],
branchName,
`${task_details}\n\nSigned-off-by: ${email}`
`${submission_summary}\n\nSigned-off-by: ${name} <${email}>`
);

// Create a pull request from the user's fork to the upstream repository
const pr = await createPullRequest(headers, githubUsername, branchName, name);
const pr = await createPullRequest(headers, githubUsername, branchName, submission_summary);

return NextResponse.json(pr, { status: 201 });
} catch (error) {
Expand Down Expand Up @@ -296,12 +298,12 @@ async function getCommitSha(headers: HeadersInit, username: string, branchName:
return data.object.sha;
}

async function createPullRequest(headers: HeadersInit, username: string, branchName: string, knowledgeName: string) {
async function createPullRequest(headers: HeadersInit, username: string, branchName: string, knowledgeSummary: string) {
const response = await fetch(`${GITHUB_API_URL}/repos/${UPSTREAM_REPO_OWNER}/${UPSTREAM_REPO_NAME}/pulls`, {
method: 'POST',
headers,
body: JSON.stringify({
title: `Add knowledge: ${knowledgeName}`,
title: `Knowledge: ${knowledgeSummary}`,
head: `${username}:${branchName}`,
base: BASE_BRANCH
})
Expand Down
20 changes: 11 additions & 9 deletions src/app/api/pr/skill/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { NextResponse } from 'next/server';
import { getToken } from 'next-auth/jwt';
import { NextRequest } from 'next/server';
import yaml from 'js-yaml';
import { SchemaVersion } from '@/types';

const GITHUB_API_URL = 'https://api.github.com';
const UPSTREAM_REPO_OWNER = 'brents-pet-robot';
const UPSTREAM_REPO_NAME = 'taxonomy-sub-testing';
const UPSTREAM_REPO_OWNER = process.env.NEXT_PUBLIC_TAXONOMY_REPO_OWNER!;
const UPSTREAM_REPO_NAME = process.env.NEXT_PUBLIC_TAXONOMY_REPO!;
const BASE_BRANCH = 'main';

export async function POST(req: NextRequest) {
Expand All @@ -28,7 +29,7 @@ export async function POST(req: NextRequest) {

try {
const body = await req.json();
const { name, email, task_description, title_work, link_work, license_work, revision, creators, questions, contexts, answers } = body;
const { name, email, task_description, submission_summary, title_work, link_work, license_work, creators, questions, contexts, answers } = body;

// Fetch GitHub username
const githubUsername = await getGitHubUsername(headers);
Expand All @@ -51,7 +52,8 @@ export async function POST(req: NextRequest) {
}

const yamlData = {
created_by: email,
created_by: githubUsername,
version: SchemaVersion,
task_description: task_description,
seed_examples: questions.map((question: string, index: number) => {
const example: SeedExample = {
Expand All @@ -68,7 +70,7 @@ export async function POST(req: NextRequest) {
const yamlString = yaml.dump(yamlData, { lineWidth: -1 });
const attributionContent = `Title of work: ${title_work}
Link to work: ${link_work}
Revision: ${revision}
Revision: -
License of the work: ${license_work}
Creator names: ${creators}
`;
Expand All @@ -89,11 +91,11 @@ Creator names: ${creators}
{ path: newAttributionFilePath, content: attributionContent }
],
branchName,
task_description
`${submission_summary}\n\nSigned-off-by: ${name} <${email}>`
);

// Create a pull request from the user's fork to the upstream repository
const pr = await createPullRequest(headers, githubUsername, branchName, name);
const pr = await createPullRequest(headers, githubUsername, branchName, submission_summary);

return NextResponse.json(pr, { status: 201 });
} catch (error) {
Expand Down Expand Up @@ -268,12 +270,12 @@ async function getCommitSha(headers: HeadersInit, username: string, branchName:
return data.object.sha;
}

async function createPullRequest(headers: HeadersInit, username: string, branchName: string, skillName: string) {
async function createPullRequest(headers: HeadersInit, username: string, branchName: string, skillSummary: string) {
const response = await fetch(`${GITHUB_API_URL}/repos/${UPSTREAM_REPO_OWNER}/${UPSTREAM_REPO_NAME}/pulls`, {
method: 'POST',
headers,
body: JSON.stringify({
title: `Add skill: ${skillName}`,
title: `Skill: ${skillSummary}`,
head: `${username}:${branchName}`,
base: BASE_BRANCH
})
Expand Down
13 changes: 8 additions & 5 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// src/app/jobs/dashboard/page.tsx
// src/app/page.tsx
'use client';

import * as React from 'react';
import { AppLayout } from '../../components/AppLayout';
import { Index } from '../../components/Dashboard';
import '@patternfly/react-core/dist/styles/base.css';
import { AppLayout } from '@/components/AppLayout';
import { Index } from '@/components/Dashboard';

const DashboardPage: React.FC = () => {
const Home: React.FunctionComponent = () => {
return (
<AppLayout>
<Index />
</AppLayout>
);
};

export default DashboardPage;
export default Home;
Loading