Skip to content

Commit

Permalink
feat(feedback): add frontend url field in configs (#1742)
Browse files Browse the repository at this point in the history
  • Loading branch information
riginoommen committed Sep 8, 2023
2 parents 2108815 + 5ea5914 commit aa761bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/feedback-service/src/feedback-config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const FeedbackConfigSchema: Schema = new Schema({
required: true,
unique: true,
},
projectFrontendUrl: {
type: String,
},
isEnabled: { type: Boolean, default: true },
sourceType: { type: String, enum: ['JIRA', 'GITLAB', 'GITHUB', 'EMAIL'], default: 'JIRA' },
sourceApiUrl: { type: String },
Expand Down
2 changes: 2 additions & 0 deletions packages/feedback-service/src/feedback-config/typedef.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type FeedbackConfigType {
sourceHeaders: [FeedbackHeaderType]
projectKey: String
feedbackEmail: String
projectFrontendUrl: String
}

input FeedbackConfigInput {
Expand All @@ -36,6 +37,7 @@ input FeedbackConfigInput {
sourceHeaders: [FeedbackHeaderInput]
projectKey: String
feedbackEmail: String
projectFrontendUrl: String
}

type Query {
Expand Down
15 changes: 12 additions & 3 deletions packages/feedback-service/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,23 @@ function createEmailTemplate(
) {
const appName = projectId.split( '/' )[ 1 ] ?? projectId;

const getPageUrl = ( str: string ) => {
try {
const url = new URL( str );
return url.toString();
} catch ( err ) {
return new URL( str, config.projectFrontendUrl ?? process.env.FEEDBACK_CLIENT!.toLowerCase() );
}
}

const pageUrl = getPageUrl(feedback.stackInfo?.path ?? '/');

const emailBody = `
Hi ${userInfo[0].cn},<br/><br/>
We have received the ${feedback.category.toLowerCase()} for the ${appName}<br/><br/>
Summary: ${feedback.summary}<br/><br/>
URL: ${new URL(process.env.FEEDBACK_CLIENT as string).origin}${
(feedback.stackInfo as any)?.path
}<br/><br/>
URL: ${pageUrl}<br/><br/>
${
feedback.ticketUrl
Expand Down
1 change: 1 addition & 0 deletions packages/feedback-service/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type FeedbackConfigType = {
}>;
projectKey: string;
feedbackEmail: string;
projectFrontendUrl: string;
};

type FeedbackConfigInput = {
Expand Down

0 comments on commit aa761bf

Please sign in to comment.