From 5f6a526ce6d54464532ff6cd630296570ce2473c Mon Sep 17 00:00:00 2001 From: Ananta Kumar Ghosh Date: Wed, 17 Jan 2024 13:25:13 +0530 Subject: [PATCH 1/4] docs: :closed_lock_with_key: add contributing file add general contributing file Ref: wrappid/.github#8 --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ef676da --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +## CONTRIBUTING +All Wrappid repositories follow the same contributing guidelines available in the following link: +https://github.com/wrappid/.github/blob/main/profile/CONTRIBUTING.md \ No newline at end of file From d828887b7120ac70c3c0555a5a8413af497d9df0 Mon Sep 17 00:00:00 2001 From: PritamIT2023 Date: Thu, 21 Mar 2024 18:48:38 +0530 Subject: [PATCH 2/4] feat(global): :sparkles: cheking github issue exist or not cheking github issue exist or not Ref: #12 --- service/functions/support.helper.ts | 60 +++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/service/functions/support.helper.ts b/service/functions/support.helper.ts index a20383e..21fb1a7 100644 --- a/service/functions/support.helper.ts +++ b/service/functions/support.helper.ts @@ -1,5 +1,12 @@ +import { configProvider } from "@wrappid/service-core"; +import fetch from "node-fetch-commonjs"; import { createIssue } from "./support.functions"; +interface ArrayUrlsTitles { + url: string; + title: string; +} + export const createReportIssuePost = async (req:any) => { try { const { @@ -12,10 +19,15 @@ export const createReportIssuePost = async (req:any) => { labels, } = req?.body || {}; + + const urlAndTitleArray: ArrayUrlsTitles[] = await getAllIssueTitles(); + if(matchString(urlAndTitleArray, title)){ + return {status:200, message: "Issue already exist" }; + } const data = await createIssue( title, - description, - stepsToCreate, + description,// + stepsToCreate,// stackTrace, JSON.parse(devInfo), JSON.parse(reporterInfo), @@ -31,4 +43,46 @@ export const createReportIssuePost = async (req:any) => { console.error(error); throw error; } -}; \ No newline at end of file +}; + + +async function getAllIssueTitles() { + try { + const response = await fetch(configProvider().github.createIssueURL, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + configProvider().github.token, + } + }); + if (!response.ok) { + throw new Error(`Error fetching issues: ${response.statusText}`); + } + const issues:any = await response.json(); + const urlAndTitleArray: ArrayUrlsTitles[] = issues.map((item: { url: string; title: string; }) => ({ + url: item.url, + title: item.title, + })); + return urlAndTitleArray; + } catch (error) { + console.log(error); + throw error; + + } + +} + +function matchString(urlAndTitleArray: ArrayUrlsTitles[], targetString: string) { + try { + const stringArray: string[] = urlAndTitleArray.map((item: {title: string; }) => item.title); + for (const string of stringArray) { + if (string.includes(targetString)) { + return true; + } + } + return false; + } catch (error) { + console.log(error); + throw error; + } +} From 7be92ef1459eb58aac718ccc11cc43011d67cba5 Mon Sep 17 00:00:00 2001 From: PritamIT2023 Date: Thu, 21 Mar 2024 21:50:39 +0530 Subject: [PATCH 3/4] feat(global): :sparkles: if issue exist create comment if issue exist create comment Ref: #12 --- service/functions/support.helper.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/service/functions/support.helper.ts b/service/functions/support.helper.ts index 21fb1a7..8ad4c6a 100644 --- a/service/functions/support.helper.ts +++ b/service/functions/support.helper.ts @@ -2,7 +2,7 @@ import { configProvider } from "@wrappid/service-core"; import fetch from "node-fetch-commonjs"; import { createIssue } from "./support.functions"; -interface ArrayUrlsTitles { +type ArrayUrlsTitles = { url: string; title: string; } @@ -22,7 +22,29 @@ export const createReportIssuePost = async (req:any) => { const urlAndTitleArray: ArrayUrlsTitles[] = await getAllIssueTitles(); if(matchString(urlAndTitleArray, title)){ - return {status:200, message: "Issue already exist" }; + const commentBody = "This is test comment from Node.js script."; + const issueUrl: string = urlAndTitleArray.find((item:ArrayUrlsTitles) => item.title === title)?.url as string; + const commentUrl: string = issueUrl + "/comments"; + const headers = { + "Content-Type": "application/json", + "Authorization": `Bearer ${configProvider().github.token}` + }; + const payload = { + body: commentBody + }; + await fetch(commentUrl, { + method: "POST", + headers, + body: JSON.stringify(payload) + }) + .then(response => { + if (!response.ok) { + throw new Error(`Error creating comment: ${response.status}`); + } + console.log("Comment created successfully!"); + }); + return {status:200, message: "Comment created successfully!" }; + } const data = await createIssue( title, From a5c2eda3e55fa492ac1f3e301325671512735b38 Mon Sep 17 00:00:00 2001 From: PritamIT2023 Date: Fri, 22 Mar 2024 15:06:32 +0530 Subject: [PATCH 4/4] feat(global): :sparkles: create comment if same isssue exist create comment if same isssue exist Ref: #12 --- service/functions/support.helper.ts | 190 +++++++++++++++++++++++++--- 1 file changed, 174 insertions(+), 16 deletions(-) diff --git a/service/functions/support.helper.ts b/service/functions/support.helper.ts index 8ad4c6a..b641711 100644 --- a/service/functions/support.helper.ts +++ b/service/functions/support.helper.ts @@ -2,9 +2,10 @@ import { configProvider } from "@wrappid/service-core"; import fetch from "node-fetch-commonjs"; import { createIssue } from "./support.functions"; -type ArrayUrlsTitles = { +type UrlsTitlesBodyObj = { url: string; title: string; + body: string } export const createReportIssuePost = async (req:any) => { @@ -19,12 +20,17 @@ export const createReportIssuePost = async (req:any) => { labels, } = req?.body || {}; - - const urlAndTitleArray: ArrayUrlsTitles[] = await getAllIssueTitles(); - if(matchString(urlAndTitleArray, title)){ - const commentBody = "This is test comment from Node.js script."; - const issueUrl: string = urlAndTitleArray.find((item:ArrayUrlsTitles) => item.title === title)?.url as string; - const commentUrl: string = issueUrl + "/comments"; + const urlAndTitleArray: UrlsTitlesBodyObj[] = await getAllIssueInfo(); + //chcke issue exist or not + if(await matchString(urlAndTitleArray, title)){ + const issueUrl: UrlsTitlesBodyObj = urlAndTitleArray.find((item:UrlsTitlesBodyObj) => item.title === title) as UrlsTitlesBodyObj; + const commentUrl: string = issueUrl.url + "/comments"; + const commentBody: string = await createCommentBody(issueUrl.body, { + currentDescription: description, + currentStepsToCreate: stepsToCreate, + currentStackTrace: stackTrace, + currentDevInfo: devInfo, + currentReporterInfo: reporterInfo}); const headers = { "Content-Type": "application/json", "Authorization": `Bearer ${configProvider().github.token}` @@ -41,15 +47,15 @@ export const createReportIssuePost = async (req:any) => { if (!response.ok) { throw new Error(`Error creating comment: ${response.status}`); } - console.log("Comment created successfully!"); }); + console.log("Comment created successfully!"); return {status:200, message: "Comment created successfully!" }; - } + const data = await createIssue( title, - description,// - stepsToCreate,// + description, + stepsToCreate, stackTrace, JSON.parse(devInfo), JSON.parse(reporterInfo), @@ -68,7 +74,7 @@ export const createReportIssuePost = async (req:any) => { }; -async function getAllIssueTitles() { +async function getAllIssueInfo(): Promise { try { const response = await fetch(configProvider().github.createIssueURL, { method: "GET", @@ -81,20 +87,19 @@ async function getAllIssueTitles() { throw new Error(`Error fetching issues: ${response.statusText}`); } const issues:any = await response.json(); - const urlAndTitleArray: ArrayUrlsTitles[] = issues.map((item: { url: string; title: string; }) => ({ + const urlAndTitleArray: UrlsTitlesBodyObj[] = issues.map((item: { url: string; title: string; body: string }) => ({ url: item.url, title: item.title, + body: item.body })); return urlAndTitleArray; } catch (error) { console.log(error); throw error; - } - } -function matchString(urlAndTitleArray: ArrayUrlsTitles[], targetString: string) { +async function matchString(urlAndTitleArray: UrlsTitlesBodyObj[], targetString: string): Promise { try { const stringArray: string[] = urlAndTitleArray.map((item: {title: string; }) => item.title); for (const string of stringArray) { @@ -108,3 +113,156 @@ function matchString(urlAndTitleArray: ArrayUrlsTitles[], targetString: string) throw error; } } + + +async function createCommentBody(issueBody: string, { + currentDescription, + currentStepsToCreate, + currentStackTrace, + currentDevInfo, + currentReporterInfo}:any): Promise { + try { + // Regular expression to match the Description section + const descriptionRegex = /## Description:\n(.*?)(?=##|\n$)/s; + const stepsToCreateRegex = /## Steps To Create:\n(.*?)\n##/s; + const stackTraceRegex = /
([\s\S]*?)<\/pre>/;
+    // const developerInfoRegex = /## Developer Information:(.*?)## Reporter Information:/s;
+    // const reporterInformationRegex = /## Reporter Information:(.*?)\|(.*)/s;
+
+    // Extract the description using match()
+    const descriptionMatch = issueBody.match(descriptionRegex);
+    const description = descriptionMatch ? descriptionMatch[1].trim() : "";
+
+    // Extracting steps to create
+    const stepsToCreateMatch = issueBody.match(stepsToCreateRegex);
+    const stepsToCreate = stepsToCreateMatch ? stepsToCreateMatch[1].trim() : "";
+
+    // Extracting stack trace
+    // const stackTracematch = stackTraceRegex.exec(issueBody);
+    const stackTracematch = issueBody.match(stackTraceRegex);
+    const stackTrace = stackTracematch ? stackTracematch[1].trim(): "";
+  
+    /*
+   // Extracting developer Info
+   const developerInfoMatch = issueBody.match(developerInfoRegex);
+   const developerInformation = developerInfoMatch ? developerInfoMatch[1].trim(): "";
+
+   //Extracting Reporter Information
+   const reporterInformatinMatch = issueBody.match(reporterInformationRegex);
+   const reporterInformaion = reporterInformatinMatch ? reporterInformatinMatch[1].trim(): "";
+    */
+
+    let commentBody = "## Description:\n";
+    if(currentDescription.trim() != description.trim() ){
+      if(currentDescription.trim() === ""){
+        commentBody += "No description provided.";
+      }else{
+        commentBody += currentDescription;
+      }
+    }else{
+      commentBody += "Same as above";
+    }
+
+    commentBody += "\n## Steps To Create:\n";
+    if(currentStepsToCreate.trim() != stepsToCreate.trim()){
+      if(currentStepsToCreate.trim() === ""){
+        commentBody += "No steps provided.";
+      }else{
+        commentBody += currentStepsToCreate;
+      }
+    }else{
+      commentBody += "Same as above";
+    }
+
+    commentBody += "\n## Stack trace:\n";
+    if(currentStackTrace.trim() != stackTrace.trim()){
+      if(currentStackTrace.trim() === ""){
+        issueBody += "
No stack trace available.
"; + }else{ + commentBody += "
" + stackTrace + "
"; + } + }else{ + commentBody += "Same as above"; + } + + /* + commentBody += "\n## Developer Information:\n"; + if(currentDevInfo.trim() != developerInformation.trim()){ + if(currentDevInfo.trim() === ""){ + commentBody += "No developer information provided."; + }else{ + currentDevInfo = JSON.parse(currentDevInfo); + commentBody += "| Key | Value |"; + commentBody += "\n|---|---|"; + commentBody += "\n| Frontend URL | " + currentDevInfo?.frontend?.url + " |"; + commentBody += "\n| Frontend Version | " + currentDevInfo?.frontend?.version + " |"; + commentBody += "\n| Backend URL | " + currentDevInfo?.backend?.url + " |"; + commentBody += "\n| Backend Version | " + currentDevInfo?.backend?.version + " |"; + commentBody += "\n| User Agent | " + currentDevInfo?.client?.userAgent + " |"; + commentBody += "\n| Device | " + currentDevInfo?.client?.device + " |"; + commentBody += "\n| Browser | " + currentDevInfo?.client?.browser + " |"; + commentBody += "\n| OS | " + currentDevInfo?.client?.os + " |"; + } + }else{ + commentBody += "Same as above"; + } + */ + + /* + commentBody += "\n## Reporter Information:\n"; + if(currentReporterInfo.trim() != reporterInformaion.trim()){ + if(currentReporterInfo.trim() === ""){ + commentBody += "No reporter information provided."; + }else{ + currentReporterInfo = JSON.parse(currentReporterInfo); + commentBody += "| Key | Value |"; + commentBody += "\n|---|---|"; + commentBody += "\n| Name | " + currentReporterInfo?.name + " |"; + commentBody += "\n| Email | " + currentReporterInfo?.email + " |"; + commentBody += "\n| Phone | " + currentReporterInfo?.phone + " |"; + commentBody += "\n| Role | " + currentReporterInfo?.role + " |"; + commentBody += "\n| Creation Time | " + currentReporterInfo?.creationTime + " |"; + } + }else{ + commentBody += "Same as above"; + } + */ + + // Developer Information + commentBody += "\n## Developer Information:\n"; + if (currentDevInfo) { + const devInfo = JSON.parse(currentDevInfo); + commentBody += "| Key | Value |"; + commentBody += "\n|---|---|"; + commentBody += "\n| Frontend URL | " + devInfo?.frontend?.url + " |"; + commentBody += "\n| Frontend Version | " + devInfo?.frontend?.version + " |"; + commentBody += "\n| Backend URL | " + devInfo?.backend?.url + " |"; + commentBody += "\n| Backend Version | " + devInfo?.backend?.version + " |"; + commentBody += "\n| User Agent | " + devInfo?.client?.userAgent + " |"; + commentBody += "\n| Device | " + devInfo?.client?.device + " |"; + commentBody += "\n| Browser | " + devInfo?.client?.browser + " |"; + commentBody += "\n| OS | " + devInfo?.client?.os + " |"; + } else { + commentBody += "No developer information provided."; + } + + // Reporter Information + commentBody += "\n## Reporter Information:\n"; + if (currentReporterInfo) { + const reporterInfo = JSON.parse(currentReporterInfo); + commentBody += "| Key | Value |"; + commentBody += "\n|---|---|"; + commentBody += "\n| Name | " + reporterInfo?.name + " |"; + commentBody += "\n| Email | " + reporterInfo?.email + " |"; + commentBody += "\n| Phone | " + reporterInfo?.phone + " |"; + commentBody += "\n| Role | " + reporterInfo?.role + " |"; + commentBody += "\n| Creation Time | " + reporterInfo?.creationTime + " |"; + } else { + commentBody += "No reporter information provided."; + } + return commentBody; + } catch (error) { + console.log(error); + throw error; + } +} \ No newline at end of file