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
75 changes: 75 additions & 0 deletions .github/workflows/enforce-draft-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Enforce Draft PR

on:
pull_request_target:
types: [opened, reopened]

permissions:
pull-requests: write

jobs:
enforce-draft:
name: Enforce Draft PR
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- name: Convert PR to draft
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const pullRequest = context.payload.pull_request;
const repo = context.repo;

// Convert to draft via GraphQL (REST API doesn't support this)
try {
await github.graphql(`
mutation($pullRequestId: ID!) {
convertPullRequestToDraft(input: { pullRequestId: $pullRequestId }) {
pullRequest {
isDraft
}
}
}
`, {
pullRequestId: pullRequest.node_id
});
} catch (error) {
core.warning(`Failed to convert PR to draft: ${error.message}`);
return;
}

// Label the PR so maintainers can filter/track violations
await github.rest.issues.addLabels({
...repo,
issue_number: pullRequest.number,
labels: ['converted-to-draft'],
});
Comment on lines +42 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The addLabels call lacks error handling. If it fails, the workflow will terminate silently without posting its explanatory comment.
Severity: MEDIUM

Suggested Fix

Wrap the addLabels call in a try/catch block to handle potential errors gracefully. This ensures that the script can continue execution or log a meaningful error, preventing a silent failure. Consider also programmatically ensuring the label exists or documenting it as a prerequisite.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: .github/workflows/enforce-draft-pr.yml#L42-L46

Potential issue: The call to `github.rest.issues.addLabels` is not wrapped in any error
handling. If this operation fails, for example, due to the `"converted-to-draft"` label
not existing in the repository or because of insufficient permissions (potentially
requiring `issues: write`), the script will terminate prematurely. This silent failure
would prevent the subsequent, explanatory comment from being posted to the pull request,
undermining the workflow's goal of educating the contributor about the draft conversion.

Did we get this right? 👍 / 👎 to inform future reviews.


// Check for existing bot comment to avoid duplicates on reopen
const comments = await github.rest.issues.listComments({
...repo,
issue_number: pullRequest.number,
});
const botComment = comments.data.find(c =>
c.user.type === 'Bot' &&
c.body.includes('automatically converted to draft')
);
if (botComment) {
core.info('Bot comment already exists, skipping.');
return;
}

const contributingUrl = `https://github.com/${repo.owner}/${repo.repo}/blob/master/CONTRIBUTING.md`;

await github.rest.issues.createComment({
...repo,
issue_number: pullRequest.number,
body: [
`This PR has been automatically converted to draft. All PRs must start as drafts per our [contributing guidelines](${contributingUrl}).`,
'',
'**Next steps:**',
'1. Ensure CI passes',
'2. Fill in the PR description completely',
'3. Mark as "Ready for review" when you\'re done'
].join('\n')
});
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ We will review your pull request as soon as possible. Thank you for contributing

You are welcome to use whatever tools you prefer for making a contribution. However, any changes you propose have to be reviewed and tested by you, a human, first, before you submit a pull request with them for the Sentry team to review. If we feel like that didn't happen, we will close the PR outright. For example, we won't review visibly AI-generated PRs from an agent instructed to look for and "fix" open issues in the repo.

## Pull Requests

All PRs must be created as **drafts**. Non-draft PRs will be automatically converted to draft. Mark your PR as "Ready for review" once:

- CI passes
- The PR description is complete (what, why, and links to relevant issues)
- You've personally reviewed your own changes

A PR should do one thing well. Don't mix functional changes with unrelated refactors or cleanup. Smaller, focused PRs are easier to review, reason about, and revert if needed.

For the full set of PR standards, see the [code submission standard](https://develop.sentry.dev/sdk/getting-started/standards/code-submission/#pull-requests).

## Development Environment

### Set up Python
Expand Down
Loading