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

lint: PR description linter #18399

Closed
wants to merge 1 commit into from
Closed

lint: PR description linter #18399

wants to merge 1 commit into from

Conversation

fjahr
Copy link
Contributor

@fjahr fjahr commented Mar 21, 2020

This is a proof of concept of my idea briefly outlined here #18380 (comment). The code is partially based on the merge script.

The new linter uses the pull request number available in the Travis env and the Github API to retrieve the PR description and checks it for common errors, currently @-prefixed GH usernames and fractional left-overs of the pull request template (identified by HTML comments). Currently, users mostly have to be reminded here manually to fix these things or they are caught in the merge process. Obviously this linter can be expanded to check for more similar issues, those are just the ones I am familiar with. For example, usernames in ACK messages could be added as well, as mentioned here: bitcoin-core/bitcoin-maintainer-tools#51

If #18380 gets merged, the HTML comments part is useless but we could put a unique string in the bottom of the pull request template and then match against that. Alternatively, this PR could be a replacement for #18358

Open question: I was not sure if the script should be more forgiving. It expects to be run in Travis and otherwise fails. I think this makes sense because the user would have to provide the PR number manually if they want to run it locally. It also fails if there is an issue with the Github API which seems to have problems quite frequently. On the other hand, if Github is down, the CI checks should probably not be running anyway.

@fjahr
Copy link
Contributor Author

fjahr commented Mar 21, 2020

Rate limiting of the Travis IPs seems to make the use of an authenticated request mandatory, added that.

@fjahr fjahr changed the title PR description linter lint: PR description linter Mar 21, 2020
@DrahtBot DrahtBot added the Tests label Mar 21, 2020
@laanwj
Copy link
Member

laanwj commented Mar 22, 2020

Concept ACK, thanks for working on this.

@practicalswift
Copy link
Contributor

Concept ACK: Automation is good

@promag
Copy link
Member

promag commented Mar 23, 2020

Concept ACK.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Concept ACK

Testing the script, I couldn't trigger a linting error with the script when run on a PR with HTML comments in the description. E.g. run on PR #18376
$ TRAVIS_PULL_REQUEST=18376 ./check-pr-description.py
didn't output anything when it should, see a421e0a for the commit message. That likely has to do with the search strings that have to be adapted (see my two code review comments plus change suggestions).

test/lint/check-pr-description.py Outdated Show resolved Hide resolved
test/lint/check-pr-description.py Outdated Show resolved Hide resolved
@maflcko
Copy link
Member

maflcko commented Mar 25, 2020

Not sure if this is worth it. If it is extended to check for @ in any comment (as suggested in the OP), it is a DOS vector where anyone can block the travis run/make it fail by just posting a comment. In that case maintainers would have to run around and remove the @ to just get travis to run.

I think it should be sufficient to have the check in the merge script

@fjahr
Copy link
Contributor Author

fjahr commented Mar 25, 2020

Not sure if this is worth it. If it is extended to check for @ in any comment (as suggested in the OP), it is a DOS vector where anyone can block the travis run/make it fail by just posting a comment. In that case maintainers would have to run around and remove the @ to just get travis to run.

I think it should be sufficient to have the check in the merge script

That makes a lot of sense, thanks!

@fjahr
Copy link
Contributor Author

fjahr commented Mar 25, 2020

Thanks to @theStack 's feedback the regex should work properly now. I also simplified the GH username regex and added some documentation.

Here are some test vectors:

Fail due to HTML tags:

$ TRAVIS_PULL_REQUEST=16439 ./check-pr-description.py

Fail due to GH username:

$ TRAVIS_PULL_REQUEST=18376 ./check-pr-description.py

Since these are active the descriptions could be fixed any day so if it does not work withthese please check first if that is the case.

For the fun of it, you can test ranges of PRs like so but you will see 404 errors for each number that is an issue and not a pull:

COUNTER=18000; while [ $COUNTER -lt 18020 ]; do TRAVIS_PULL_REQUEST=$COUNTER test/lint/check-pr-description.py; let COUNTER+=1; done

@fjahr
Copy link
Contributor Author

fjahr commented Mar 25, 2020

I thought there was a github access token available in the git config inside Travis but it appears their isn't and not running into rate limiting last time was a false positive. I am trying to find out the variable name if there is one available in the Travis environment, otherwise it would need to be added.

@theStack
Copy link
Contributor

FWIW, with the help of a quick git log --grep="-->" and further manual inspection I could find two false positives, i.e. PRs that contain no HTML comments but still the linter would complain:

@fjahr
Copy link
Contributor Author

fjahr commented Mar 30, 2020

FWIW, with the help of a quick git log --grep="-->" and further manual inspection I could find two false positives, i.e. PRs that contain no HTML comments but still the linter would complain:

Thanks for discovering these. So yes, the current version does give false positives any time someone wants to write something in the PR description that actually includes HTML comments. The only effective way I could think of to mitigate that would be to use the solution with the unique string in the template. It would work like this: at the bottom of the template, there is something like TEMPLEATE_END_PLEASE_REMOVE_ME or so and then this linter checks for that string. I am happy to hear feedback if that solution is preferred to prevent these false positives.

@fjahr fjahr force-pushed the pr-desc-lint branch 2 times, most recently from 2b23a3e to 3387211 Compare April 3, 2020 22:29
@fjahr
Copy link
Contributor Author

fjahr commented Apr 4, 2020

Unfortunately, it looks like this is blocked. I was trying to get a Github Oauth Token into the Travis build environment as a secure (encrypted) variable but this variable can still not be accessed by pull requests triggered through forks since the variable would be exposed to unknown code (see travis docs) This makes sense and I currently only see this working if the pull body does get added to the standard Travis environment variables. There exists an issue for this travis-ci/travis-ci#9302 and a pull request is open to add the title at least travis-ci/travis-build#1319 but it has been open for 2 years.

I am happy to hear if there are other ideas on how to achieve this. Otherwise, I will close this and reopen when the pull body becomes available in Travis somehow. But I don't think there are any other obvious solutions as they should have come up in the Travis issues on this topic.

@fjahr fjahr closed this Apr 4, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants