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

Enable GitAuto forge to call GitAuto with payload #24

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Conversation

hiroshinishio
Copy link
Contributor

No description provided.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @hiroshinishio - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing commented-out code in getIssueDetails response object - if this data isn't needed, remove it entirely; if it might be needed later, add a TODO comment explaining why it's preserved
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

issueId,
repository: selectedRepo,
}),
body: JSON.stringify({ ...payload }),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider validating payload fields before sending to external service

Spreading the entire payload without validation could lead to sending unexpected data. Consider explicitly mapping required fields.

Suggested implementation:

    body: JSON.stringify({
      issueId: payload.issueId,
      repository: payload.repository,
    }),

For even better validation, you might want to add:

  1. Type checking before the JSON.stringify:
if (!payload.issueId || !payload.repository) {
  throw new Error('Missing required fields: issueId and repository are required');
}
  1. Consider using a validation library like Joi or Zod if you want more robust validation
  2. Add TypeScript types if the project uses TypeScript

return await response.json();
});

// Convert Atlassian Document Format to Markdown
const adfToMarkdown = (adf) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider extracting common text content logic and flattening the code structure in the ADF to Markdown conversion.

The adfToMarkdown function can be simplified by extracting common patterns and reducing nesting. Here's a cleaner approach:

const getTextContent = (content) => {
  if (!content) return '';
  return content.map(item => item.text || '').join('');
};

const adfToMarkdown = (adf) => {
  if (!adf?.content) return '';

  return adf.content.map((block) => {
    const content = block.content || [];

    switch (block.type) {
      case 'paragraph':
        return getTextContent(content) + '\n\n';
      case 'heading':
        const level = block.attrs?.level || 1;
        return '#'.repeat(level) + ' ' + getTextContent(content) + '\n\n';
      case 'bulletList':
        return content.map(item => `- ${getTextContent(item.content)}`).join('\n') + '\n\n';
      case 'orderedList':
        return content.map((item, i) => `${i + 1}. ${getTextContent(item.content)}`).join('\n') + '\n\n';
      case 'codeBlock':
        return '```\n' + getTextContent(content) + '\n```\n\n';
      default:
        return '';
    }
  }).join('').trim();
};

This refactoring:

  1. Extracts common text content mapping into getTextContent
  2. Reduces nesting by flattening the structure
  3. Maintains null safety while being more readable
  4. Eliminates redundant optional chaining

@hiroshinishio hiroshinishio merged commit 2fa60f2 into main Dec 10, 2024
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch December 10, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant