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
@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)
```
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'
]
}
},
```
... 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
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!
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.
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.
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
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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
--dryoption 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_TOKENandGITHUB_TOKENor add them to the.envfile (see.env.example).@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:
@silverbucket I think you didn't set the
GITHUB_TOKENandGITEA_TOKENenvironment variables. See last part of the PR description.Weird: I already had a
GITHUB_TOKENin my global environment from a different program, but not aGITEA_TOKEN. I got one error from a Gitea repo, but it looks like the rest all worked, including Gitea:... 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.
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!
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.
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.
OK, got it. Not sure why it didn't work with my token then.
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.