Create contributions for pull request reviews #64

Merged
galfert merged 5 commits from feature/49-code_review_kredits into master 2021-01-29 10:41:01 +00:00
galfert commented 2021-01-12 14:56:26 +00:00 (Migrated from github.com)

Closes #49

This script aggregates all reviews for pull requests to any Kosmos projects (on Github and Gitea) that were merged in a given timeframe. It creates a single Kredits contribution per user for all those reviews.

Running the script without any arguments prompts a list and description of all arguments.

At the moment it does't create the actual contributions yet, because I don't have a working dev setup for the contracts yet. You can use the --dry option for a dry run that lists the contribution data.

The list of repositories is configured in repos.json.

EDIT: Only thing needed for testing the script is a Gitea and Github API token. Set them as environment variables GITEA_TOKEN and GITHUB_TOKEN or add them to the .env file (see .env.example).

Closes #49 This script aggregates all reviews for pull requests to any Kosmos projects (on Github and Gitea) that were merged in a given timeframe. It creates a single Kredits contribution per user for all those reviews. Running the script without any arguments prompts a list and description of all arguments. At the moment it does't create the actual contributions yet, because I don't have a working dev setup for the contracts yet. You can use the `--dry` option for a dry run that lists the contribution data. The list of repositories is configured in `repos.json`. EDIT: Only thing needed for testing the script is a Gitea and Github API token. Set them as environment variables `GITEA_TOKEN` and `GITHUB_TOKEN` or add them to the `.env` file (see `.env.example`).
bumi (Migrated from github.com) reviewed 2021-01-12 14:56:26 +00:00
silverbucket commented 2021-01-27 12:52:02 +00:00 (Migrated from github.com)

@galfert I tried to give this a dry run, I'm probably doing something wrong - this is my first time touching this repo. Here's what I tried:

(feature/49-code_review_kredits)
$ ./scripts/review-kredits.js --dry --start 2020-11-01
/Users/njenning/code/projects/hubot-kredits/scripts/lib/github-reviews.js:47
        let pullRequests = result.filter(pr => {
                                  ^

TypeError: result.filter is not a function
    at /Users/njenning/code/projects/hubot-kredits/scripts/lib/github-reviews.js:47:35
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async Promise.all (index 3)
    at async GithubReviews.getReviewContributions (/Users/njenning/code/projects/hubot-kredits/scripts/lib/github-reviews.js:31:5)
    at async Promise.all (index 0)
    at async Promise.all (index 1)
@galfert I tried to give this a dry run, I'm probably doing something wrong - this is my first time touching this repo. Here's what I tried: ``` (feature/49-code_review_kredits) $ ./scripts/review-kredits.js --dry --start 2020-11-01 /Users/njenning/code/projects/hubot-kredits/scripts/lib/github-reviews.js:47 let pullRequests = result.filter(pr => { ^ TypeError: result.filter is not a function at /Users/njenning/code/projects/hubot-kredits/scripts/lib/github-reviews.js:47:35 at processTicksAndRejections (node:internal/process/task_queues:93:5) at async Promise.all (index 3) at async GithubReviews.getReviewContributions (/Users/njenning/code/projects/hubot-kredits/scripts/lib/github-reviews.js:31:5) at async Promise.all (index 0) at async Promise.all (index 1) ```
galfert commented 2021-01-27 23:04:39 +00:00 (Migrated from github.com)

@silverbucket I think you didn't set the GITHUB_TOKEN and GITEA_TOKEN environment variables. See last part of the PR description.

@silverbucket I think you didn't set the `GITHUB_TOKEN` and `GITEA_TOKEN` environment variables. See last part of the PR description.
raucao commented 2021-01-28 11:33:00 +00:00 (Migrated from github.com)

Weird: I already had a GITHUB_TOKEN in my global environment from a different program, but not a GITEA_TOKEN. I got one error from a Gitea repo, but it looks like the rest all worked, including Gitea:

(feature/49-code_review_kredits) ~/src/kosmos/kredits/hubot-kredits $ ./scripts/review-kredits.js --dry --start 2020-11-01                                                   
failed to fetch reviews for repo kosmos/chef, PR 294: invalid json response body at https://gitea.kosmos.org/api/v1/repos/kosmos/chef/pulls/294/reviews reason: Unexpected to
ken < in JSON at position 0                                                                                                                                                  
contributions:                                                                                                                                                               
{                                                                                                                                                                            
  galfert: {                                                                                                                                                                 
    contributorId: 4,                                                                                                                                                        
    contributorIpfsHash: 'QmTY6n2TUhRGbRCTk4j7SChNCEPSXH7d8DBJT1Wo94VhS4',                                                                                                   
    date: '2021-01-28',                                                                                                                                                      
    time: '11:27:05Z',                                                                                                                                                       
    amount: 1600,                                                                                                                                                            
    kind: 'dev',                                                                                                                                                             
    description: 'PR reviews',                                                                                                                                               
    details: {                                                                                                                                                               
      pullRequests: [                                                                                                                                                        
        'https://gitea.kosmos.org/kosmos/wormhole/pulls/2',                                                                                                                  
        'https://gitea.kosmos.org/kosmos/akkounts/pulls/13',                                                                                                                 
        'https://gitea.kosmos.org/kosmos/akkounts/pulls/9',                                                                                                                  
        'https://gitea.kosmos.org/kosmos/chef/pulls/266',                                                                                                                    
        'https://gitea.kosmos.org/kosmos/chef/pulls/273',
        'https://github.com/sockethub/sockethub/pull/315',
        'https://github.com/sockethub/sockethub/pull/302',
        'https://github.com/sockethub/sockethub/pull/303'
      ]
    }
  },
Weird: I already had a `GITHUB_TOKEN` in my global environment from a different program, but not a `GITEA_TOKEN`. I got one error from a Gitea repo, but it looks like the rest all worked, including Gitea: ```plain (feature/49-code_review_kredits) ~/src/kosmos/kredits/hubot-kredits $ ./scripts/review-kredits.js --dry --start 2020-11-01 failed to fetch reviews for repo kosmos/chef, PR 294: invalid json response body at https://gitea.kosmos.org/api/v1/repos/kosmos/chef/pulls/294/reviews reason: Unexpected to ken < in JSON at position 0 contributions: { galfert: { contributorId: 4, contributorIpfsHash: 'QmTY6n2TUhRGbRCTk4j7SChNCEPSXH7d8DBJT1Wo94VhS4', date: '2021-01-28', time: '11:27:05Z', amount: 1600, kind: 'dev', description: 'PR reviews', details: { pullRequests: [ 'https://gitea.kosmos.org/kosmos/wormhole/pulls/2', 'https://gitea.kosmos.org/kosmos/akkounts/pulls/13', 'https://gitea.kosmos.org/kosmos/akkounts/pulls/9', 'https://gitea.kosmos.org/kosmos/chef/pulls/266', 'https://gitea.kosmos.org/kosmos/chef/pulls/273', 'https://github.com/sockethub/sockethub/pull/315', 'https://github.com/sockethub/sockethub/pull/302', 'https://github.com/sockethub/sockethub/pull/303' ] } }, ```
raucao commented 2021-01-28 11:38:51 +00:00 (Migrated from github.com)

... the error I'm seeing is a bug in Gitea. It produces a 500 response for me, when looking at it without being authenticated.

Edit: I added a dotenv config with a Gitea API token, but still seeing the same error.
Edit 2: I had a look, and even with the token I get a 500 in the script (vs. a good response in the browser while authed). The review for which I get the 500 is actually still "pending" and the PR is closed. So it's some kind of edge case bug. The rest looks fine to me, but I think we don't need API tokens at all for public Gitea repos.

... the error I'm seeing is a bug in Gitea. It produces a 500 response for me, when looking at it without being authenticated. Edit: I added a dotenv config with a Gitea API token, but still seeing the same error. Edit 2: I had a look, and even with the token I get a 500 in the script (vs. a good response in the browser while authed). The review for which I get the 500 is actually still "pending" and the PR is closed. So it's some kind of edge case bug. The rest looks fine to me, but I think we don't need API tokens at all for public Gitea repos.
raucao (Migrated from github.com) approved these changes 2021-01-28 12:11:28 +00:00
raucao (Migrated from github.com) left a comment

Nice! 👍

As stated in my last comment, I don't think we need API tokens for Gitea. I can access the public repos' endpoints without authentication.

I thought a bit about displaying in Kredits Web, and I think the format is OK for that already. We can implement conditional loading of details in that view if necessary.

However, we do still need to adjust the description of the contributions!

Nice! :+1: As stated in my last comment, I don't think we need API tokens for Gitea. I can access the public repos' endpoints without authentication. I thought a bit about displaying in Kredits Web, and I think the format is OK for that already. We can implement conditional loading of details in that view if necessary. However, we do still need to adjust the description of the contributions!
galfert commented 2021-01-28 15:16:51 +00:00 (Migrated from github.com)

I think the Gitea API token is needed. There is a pretty low limit for unauthenticated requests.

I also got the same error when not setting the API token, but with token I don't get any error.

I think the Gitea API token is needed. There is a pretty low limit for unauthenticated requests. I also got the same error when not setting the API token, but with token I don't get any error.
silverbucket commented 2021-01-28 15:20:14 +00:00 (Migrated from github.com)

Can we provide a useful error message in that case?

Can we provide a useful error message in that case?
raucao commented 2021-01-28 15:23:01 +00:00 (Migrated from github.com)

Can we provide a useful error message in that case?

Later, sure. This PR is just about pure functionality, not UX. It is not the actual hubot integration yet.

> Can we provide a useful error message in that case? Later, sure. This PR is just about pure functionality, not UX. It is not the actual hubot integration yet.
raucao commented 2021-01-28 15:23:55 +00:00 (Migrated from github.com)

I think the Gitea API token is needed. There is a pretty low limit for unauthenticated requests.

OK, got it. Not sure why it didn't work with my token then.

> I think the Gitea API token is needed. There is a pretty low limit for unauthenticated requests. OK, got it. Not sure why it didn't work with my token then.
silverbucket (Migrated from github.com) approved these changes 2021-01-28 15:38:38 +00:00
galfert commented 2021-01-29 10:19:45 +00:00 (Migrated from github.com)

I've added an error message when any of the API tokens are missing.

Also the description contains the timeframe now.

I will add the code for wallet setup and actual contribution creation in a separate PR when this has been merged.

I've added an error message when any of the API tokens are missing. Also the description contains the timeframe now. I will add the code for wallet setup and actual contribution creation in a separate PR when this has been merged.
raucao added the
kredits-3
label 2025-01-23 21:24:42 +00:00
Sign in to join this conversation.
No description provided.