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

Reassign PRs back to the author if they haven't filled in the PR description at the time of opening it. #326

Open
seanlip opened this issue Jun 21, 2023 · 6 comments
Labels

Comments

@seanlip
Copy link
Member

seanlip commented Jun 21, 2023

Is your feature request related to a problem? Please describe.

Sometimes PRs are opened without an adequate description. This makes it hard for reviewers to review the PR.

Describe the solution you'd like

Oppiabot should reassign the PR back to the author if the PR description is not filled in. (It's fine to use #N/A for point 1 if there's no issue number, but point 2 should always be fully filled in.)

@lalitkumawat1m
Copy link

hey @seanlip, I am willing to work on this issue, please assign me this issue.

@seanlip
Copy link
Member Author

seanlip commented Jul 12, 2023

@lalitkumawat1m Per the guidance at https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue, please provide an explanation of what your PR will do (with names of files you're changing, what you plan to change in each file, etc.). If it looks good, we can assign you to this issue.

Please also follow the other instructions on that wiki page if you have not yet done so. Thanks!

@seanlip seanlip added enhancement New feature or request Work: Low labels Nov 30, 2023
@Flying-Pegasus
Copy link
Contributor

Hello, @seanlip I am interested in solving this issue please assign it to me.

@seanlip
Copy link
Member Author

seanlip commented Dec 9, 2024

@Flying-Pegasus Per the guidance at https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue, please provide an explanation of what your PR will do (with names of files you're changing, what you plan to change in each file, etc.), as well as a video showing that the changes work correctly on your local machine. If it looks good, we can assign you to this issue.

Please also follow the other instructions on that wiki page if you have not yet done so. Thanks!

@Flying-Pegasus
Copy link
Contributor

Flying-Pegasus commented Dec 10, 2024

Proposed Changes

  1. Updating checkPullRequestTemplate.js
    We will expand the existing checkPullRequestTemplate function to include the validation for missing sections in the PR body. This function will return an array of missing sections if the template is incomplete.

Changes in checkPullRequestTemplate.js:

const checkTemplate = async (pullRequestBody) => {
  const missingSections = [];

  // Check for "Overview" section
  if (!pullRequestBody.includes('### Overview')) {
    missingSections.push('Overview');
  }

  // Check for "Checklist" section
  if (!pullRequestBody.includes('### Checklist')) {
    missingSections.push('Checklist');
  }

  // Check for "Proof of Changes" section
  if (!pullRequestBody.includes('### Proof of changes')) {
    missingSections.push('Proof of Changes');
  }

  return missingSections;
}

module.exports = {
  checkTemplate,
};
  1. Updating index.js
    Integrate the updated checkTemplate function into the bot's workflow. When a PR is opened or updated, the bot will:
  • Call checkTemplate to validate the PR body.
  • Comment on the PR with the list of missing sections.
  • Reassign the PR back to the author.

Changes in index.js:

const { checkTemplate } = require('./checkPullRequestTemplate');

robot.on('pull_request.opened', async (context) => {
  const prBody = context.payload.pull_request.body;
  const missingSections = checkTemplate(prBody);

  if (missingSections.length > 0) {
    const commentBody = `Hi @${context.payload.pull_request.user.login}, please complete the following sections in your PR description:\n` +
                        missingSections.map(section => `- ${section}`).join('\n') + 
                        `\n\nThank you!`;

    // Post a comment with the missing sections
    await context.github.issues.createComment(context.issue({ body: commentBody }));

    // Assign the PR back to the author
    await context.github.issues.addAssignees(context.issue({
      assignees: [context.payload.pull_request.user.login],
    }));
  }
});
  1. Updating checkPullRequestTemplateSpec.js
    Add test cases to verify the updated checkTemplate function's behavior. These tests will check if the function correctly identifies missing sections in different PR templates.

Changes in checkPullRequestTemplateSpec.js:

const { checkTemplate } = require('../checkPullRequestTemplate');

describe('checkTemplate', () => {
  it('should return missing sections for an incomplete PR body', () => {
    const prBody = '### Overview\nSome text\n\n### Proof of changes\nSome changes';
    const missingSections = checkTemplate(prBody);
    expect(missingSections).toEqual(['Checklist']);
  });

  it('should return no missing sections for a complete PR body', () => {
    const prBody = '### Overview\nSome text\n\n### Checklist\n- [x] Task 1\n\n### Proof of changes\nSome changes';
    const missingSections = checkTemplate(prBody);
    expect(missingSections).toHaveLength(0);
  });

  it('should return all sections if the PR body is empty', () => {
    const prBody = '';
    const missingSections = checkTemplate(prBody);
    expect(missingSections).toEqual(['Overview', 'Checklist', 'Proof of Changes']);
  });
});

Changes

1. `checkPullRequestTemplate.js`: Update the checkTemplate function to validate all required sections. 2. `index.js`: Use the updated checkTemplate function to handle incomplete PRs, post comments, and reassign them to the author. 3. `checkPullRequestTemplateSpec.js`: Add unit tests to ensure the checkTemplate function works as expected with different PR body inputs.

@seanlip

@seanlip
Copy link
Member Author

seanlip commented Dec 11, 2024

Thanks @Flying-Pegasus, I need to see a video demo of this working (see my previous comment). See oppia/stale-review-request-notifier#4 (comment) for an example -- thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

3 participants