Skip to content
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
9 changes: 5 additions & 4 deletions src/app/api/pr/knowledge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function POST(req: NextRequest) {

try {
const body = await req.json();
const { content, name, email, submission_summary, attribution, filePath } = body;
const { content, attribution, name, email, submissionSummary, documentOutline, filePath } = body;

const knowledgeData: KnowledgeYamlData = yaml.load(content) as KnowledgeYamlData;
const attributionData: AttributionData = attribution;
Expand Down Expand Up @@ -78,11 +78,11 @@ Creator names: ${attributionData.creator_names}
{ path: newAttributionFilePath, content: attributionContent }
],
branchName,
`${submission_summary}\n\nSigned-off-by: ${name} <${email}>`
`${submissionSummary}\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, submission_summary);
const pr = await createPullRequest(headers, githubUsername, branchName, submissionSummary, documentOutline);

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

async function createPullRequest(headers: HeadersInit, username: string, branchName: string, knowledgeSummary: string) {
async function createPullRequest(headers: HeadersInit, username: string, branchName: string, knowledgeSummary: string, documentOutline: string) {
const response = await fetch(`${GITHUB_API_URL}/repos/${UPSTREAM_REPO_OWNER}/${UPSTREAM_REPO_NAME}/pulls`, {
method: 'POST',
headers,
body: JSON.stringify({
title: `Knowledge: ${knowledgeSummary}`,
head: `${username}:${branchName}`,
body: documentOutline,
base: BASE_BRANCH
})
});
Expand Down
14 changes: 12 additions & 2 deletions src/components/Contribute/Knowledge/Submit/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ const Submit: React.FC<Props> = ({ knowledgeFormData, setActionGroupAlertContent
const name = knowledgeFormData.name;
const email = knowledgeFormData.email;
const submissionSummary = knowledgeFormData.submissionSummary;
const documentOutline = knowledgeFormData.documentOutline;
const response = await fetch('/api/pr/knowledge', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ content: yamlString, attribution: attributionData, name, email, submissionSummary, filePath: sanitizedFilePath })
body: JSON.stringify({
content: yamlString,
attribution: attributionData,
name,
email,
submissionSummary,
documentOutline,
filePath: sanitizedFilePath
})
});

if (!response.ok) {
Expand All @@ -76,7 +85,8 @@ const Submit: React.FC<Props> = ({ knowledgeFormData, setActionGroupAlertContent
const result = await response.json();
const actionGroupAlertContent: ActionGroupAlertContent = {
title: 'Knowledge contribution submitted successfully!',
message: `A new pull request has been created for your knowledge submission ${result.html_url}`,
message: `A new pull request has been created for your knowledge submission.`,
url: `${result.html_url}`,
success: true
};
setActionGroupAlertContent(actionGroupAlertContent);
Expand Down
8 changes: 7 additions & 1 deletion src/components/Contribute/Knowledge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface KnowledgeFormData {
export interface ActionGroupAlertContent {
title: string;
message: string;
url?: string;
success: boolean;
}

Expand Down Expand Up @@ -370,7 +371,12 @@ export const KnowledgeForm: React.FunctionComponent = () => {
title={actionGroupAlertContent.title}
actionClose={<AlertActionCloseButton onClose={onCloseActionGroupAlert} />}
>
{actionGroupAlertContent.message}
<p>
{actionGroupAlertContent.message}{' '}
<a href={actionGroupAlertContent.url} target="_blank" rel="noreferrer">
{actionGroupAlertContent.url}
</a>
</p>
</Alert>
)}
</Form>
Expand Down