Giter VIP home page Giter VIP logo

label-approved's Issues

a_u=None edge case

I hit an edge case when relabelling NixOS/nixpkgs#301947, where the first approver (@a-n-n-a-l-e-e) deleted their account.

INFO:root:Processing 301947
INFO:root:lastappdate: 2024-04-06 11:06:06
INFO:root:lastcommitdate: 2024-04-05 23:44:16
INFO:root:Removing label '12.approvals: 2' from PR: '301947' https://github.com/NixOS/nixpkgs/pull/301947
INFO:root:Adding label '12.approvals: 1' to PR: '301947' https://github.com/NixOS/nixpkgs/pull/301947
Traceback (most recent call last):
  File "/nix/store/62r1p3rnaa0qw0fms8pw3i0q07if6xyp-label-approved-0.1.0/bin/.label-approved-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/62r1p3rnaa0qw0fms8pw3i0q07if6xyp-label-approved-0.1.0/lib/python3.10/site-packages/label_approved/cli.py", line 191, in main
    process_pr(g_h, p_r_as_issue.as_pull_request(), dry_run=args.dry_run)
  File "/nix/store/62r1p3rnaa0qw0fms8pw3i0q07if6xyp-label-approved-0.1.0/lib/python3.10/site-packages/label_approved/cli.py", line 148, in process_pr
    if a_u.login.lower() in maintainers:
AttributeError: 'NoneType' object has no attribute 'login'

GraphQL API integration

As described in #11, it is easy to run into quota issues. Indeed, if one calls p_r.get_commits(), p_r.get_reviews(), p_r.get_labels() for each PR, that's already 3000 REST API requests for a search containing 1000 PRs, making it impossible to iterate over Nixpkgs in one or two hours.

Instead, the following GraphQL query retrieves the 100 most recent PRs, each with the last 100 commits, comments, labels and reviews, largely sufficient to determine the number of approvals in these PRs and the list of PRs to label or unlabel. By adding "created:<=2024-01-01T00:00:00Z", corresponding to createdAt of the oldest PR of the previous query, iterating over Nixpkgs costs less than 60 GraphQL API requests, or less than five minutes.

query {
  rateLimit {
    limit
    cost
    remaining
    resetAt
  }
  search(
    first: 100,
    query: "repo:NixOS/nixpkgs is:pr is:open",
    type: ISSUE,
  ) {
    issueCount
    nodes {
      ... on PullRequest {
        id
        number
        createdAt
        commits(last: 100) {
          edges {
            node {
              commit {
                committedDate
              }
            }
          }
        }
        comments(last: 100) {
          edges {
            node {
              createdAt
            }
          }
        }
        labels(last: 100) {
          edges {
            node {
              id
              name
            }
          }
        }
        reviews(last: 100) {
          edges {
            node {
              state
              submittedAt
            }
          }
        }
      }
    }
  }
}

Restructure to be runnable as a GitHub action

There are several drawbacks to the current "crawling" approach used by this tool:

  • Easily runs into quota issues
  • Can't process more than the last 1K PRs by ID (due to GH search API limitations, maybe?)
  • High latency since the whole set of open PRs needs to be recrawled on every run

I suggest the following complementary mode of operation:

  • Add a mode to run only on one PR, whose ID is provided on the command line.
  • Add all the scaffolding to be able to run this tool as a GitHub action.
  • Register this action to run on PR review events on nixpkgs.

Happy to take care of this myself (want to share commit privileges / future maintenance? :p), I really just want this to finally happen automatically on nixpkgs.

Suggestion: Do not subtract from approvals if there were no code changes

When someone very clearly expresses their approval in a comment, but does not use the GitHub feature to signal approval, I sometimes increase the label-based approval counter myself (to attract attention of potential mergers). Of course I could ask the person that commented favorably but did not use the GitHub feature to do exactly that, but this requires another roundtrip (I comment, they receive a notification on their end, they approve, and only then future runs will increase the label-based counter, or I do it myself).

I noticed that in these cases, the tool sometimes decreases the number of approvals, see e.g. NixOS/nixpkgs#311986 where there was approval clearly expressed in a comment, I set the label, and later @wegank ran the tool which decreased the counter.

I therefore propose that under the condition that there were no new commits in the PR, the number of approvals should not be decreased automatically.

If people that increase the label-based approval counter manually (like I do) are honest, this should work out pretty nicely.

label_dict key=0 edge case

Looks like I hit an edge case, where approval_count was 0, which generally shouldn't be a problem.

INFO:root:Processing 213835
INFO:root:lastappdate: 2023-01-31 22:11:31
INFO:root:lastcommitdate: 2023-01-31 19:15:12
Traceback (most recent call last):
  File "/nix/store/i7bzfdg5alslnxr97qh7ia0zn6gh6sf8-label-approved-0.1.0/bin/.label-approved-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/i7bzfdg5alslnxr97qh7ia0zn6gh6sf8-label-approved-0.1.0/lib/python3.10/site-packages/label_approved/cli.py", line 147, in main
    label_to_add = label_dict[pr_object.new_label]
KeyError: 0

NixOS/nixpkgs#213835

Screenshot 2023-02-02 at 02-29-27 coursera-dl fix api version problems by binarin · Pull Request #213835 · NixOS_nixpkgs

With debug

DEBUG:urllib3.connectionpool:https://api.github.com:443 "GET /repos/NixOS/nixpkgs/issues/213835/labels HTTP/1.1" 200 None
DEBUG:github.Requester:GET https://api.github.com/repos/NixOS/nixpkgs/issues/213835/labels {'Authorization': 'token (oauth token removed)', 'User-Agent': 'PyGithub/Python'} None ==> 200 {'server': 'GitHub.com', 'date': 'Thu, 02 Feb 2023 01:27:28 GMT', 'content-type': 'application/json; charset=utf-8', 'transfer-encoding': 'chunked', 'cache-control': 'private, max-age=60, s-maxage=60', 'vary': 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With', 'etag': 'W/"b18bc22cbbf9444502d42f5d57d9894a74625a89b01eff3dd1df581ce0b67434"', 'last-modified': 'Wed, 01 Feb 2023 02:54:16 GMT', 'x-oauth-scopes': 'repo', 'x-accepted-oauth-scopes': 'repo', 'github-authentication-token-expiration': '2023-02-08 01:25:57 UTC', 'x-github-media-type': 'github.v3; format=json', 'x-github-api-version-selected': '2022-11-28', 'x-ratelimit-limit': '5000', 'x-ratelimit-remaining': '3728', 'x-ratelimit-reset': '1675301677', 'x-ratelimit-used': '1272', 'x-ratelimit-resource': 'core', 'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset', 'access-control-allow-origin': '*', 'strict-transport-security': 'max-age=31536000; includeSubdomains; preload', 'x-frame-options': 'deny', 'x-content-type-options': 'nosniff', 'x-xss-protection': '0', 'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'content-security-policy': "default-src 'none'", 'content-encoding': 'gzip', 'x-github-request-id': 'E7CC:37CE:18FD4:19825:63DB1180'} [{"id":731733923,"node_id":"MDU6TGFiZWw3MzE3MzM5MjM=","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/10.rebuild-linux:%201-10","name":"10.rebuild-linux: 1-10","color":"eeffee","default":false,"description":null},{"id":731735222,"node_id":"MDU6TGFiZWw3MzE3MzUyMjI=","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/10.rebuild-darwin:%201-10","name":"10.rebuild-darwin: 1-10","color":"eeffee","default":false,"description":null},{"id":1955058051,"node_id":"MDU6TGFiZWwxOTU1MDU4MDUx","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/10.rebuild-darwin:%201","name":"10.rebuild-darwin: 1","color":"ededed","default":false,"description":null},{"id":1955058054,"node_id":"MDU6TGFiZWwxOTU1MDU4MDU0","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/10.rebuild-linux:%201","name":"10.rebuild-linux: 1","color":"ededed","default":false,"description":null},{"id":4022792890,"node_id":"LA_kwDOAEVQ_M7vxvK6","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/12.approvals:%201","name":"12.approvals: 1","color":"0E8A16","default":false,"description":""},{"id":4061482046,"node_id":"LA_kwDOAEVQ_M7yFUw-","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/12.approved-by:%20package-maintainer","name":"12.approved-by: package-maintainer","color":"0E8A16","default":false,"description":""},{"id":4826074325,"node_id":"LA_kwDOAEVQ_M8AAAABH6gM1Q","url":"https://api.github.com/repos/NixOS/nixpkgs/labels/backport%20release-22.11","name":"backport release-22.11","color":"13DBD5","default":false,"description":"Backport PR automatically"}]
DEBUG:root:PrWithApprovals(p_r=PullRequest(title="coursera-dl: fix api version problems", number=213835), new_label=0, previous_label=1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.