Comments (8)
Thanks @orta and @Antondomashnev for the feedback.
In particular thanks to @Antondomashnev I found that Octokit provides a method to get commits
client = Octokit::Client.new(:access_token => '...')
client.commits(repo, path: '/path/to/file')
which I'm able to use to get an array objects like:
{ author: '@mokagio', commits_count: 42 }
Which we can use to suggest reviewers base on commits count or most recent authors.
I'll submit a PR soonish.
Thanks again 😄 .
from danger-mention.
It would have to derive the information locally, rather than scraping the website - totally feasible, but would need work to do so
from danger-mention.
I had a though on this, and the solution I came up with is not ideal.
The problem is that as far as I can see there is not GitHub API to retrieve the blame for a given file. This is somehow confirmed by the fact that if you search for blame in Octokit you get no results. There seem to though an early access blame GraphQL API.
So this leaves us to have to retrieve the information locally, and this is where things slightly break.
You can get the list of committers for a file like this:
$ git shortlog -sne path/to/file
4 Giovanni Lodi <[email protected]>
2 Peter Parker <[email protected]>
1 Tony Stark <[email protected]>
We can also get the list of all the contributors to a repo via Octokit:
client = Octokit::Client.new(:access_token => '...')
contributors = client.contributors('danger/danger')
This API only returns partial information about the users, but we can use the login
property to get the actual user object.
contributors.map { |c| c[:login] }.each do |login|
user = client.user(login)
end
This is how my user looks
mokagio = client.user('mokagio')
puts "#{mokagio.login} - #{mokagio.name} - #{mokagio.email}"
# => mokagio - Giovanni Lodi -
# ^ the email is nil! 😱
My email is nil because I chose not to show it publicly in the GitHub settings, as I'm assuming many other user would do to avoid spamming.
So, we have a way to get an array of name + emails of committers to each file, and we can use them to get their GitHub username, which we can then insert in the Danger message. But ☝️ , that works only if the information on GitHub is in sync with the Git user.name
and user.email
.
I wouldn't be surprised if many users had a different name and email from the one they used in their Git configuration.
Does this approach make sense? It's not very robust hey 😞 . Does anyone know if there's better API that we could use?
One option could be to use this only for private repos, and use web scraping for public ones?
from danger-mention.
Depending on depth that you want to go into it, you could potentially look for the last commit by the email provided, then use the GitHub API for that one commit to see if you have any GitHub account metadata for the email too?
from danger-mention.
Hey @mokagio after a quick search I've found something that may be useful to get the commiters.
What if you get the list of all commits containing the specific file in repository. In the response you'll receive the commit
object which contains the information about commiter.
Please correct me If I'm wrong with assumption 😄
from danger-mention.
rock
from danger-mention.
Hey @mokagio do you have any half-baked PR that someone could take over or do we need to start from scratch here! Happy holidays! 🎄
from danger-mention.
Private, non enterprise github repos, do not currently work with danger runs on CI? Is that a correct understanding? Is it true that only Enterprise github repos are supported under CI? My error in Jenkins when I try to post back to http://github.com/duncwa.
from danger-mention.
Related Issues (10)
- Better strategy of downloading blame information HOT 1
- Invalid `Dangerfile` file: 401 Unauthorized HOT 2
- [!] Invalid `Dangerfile` file: 404 Not Found HOT 2
- Allow users to supply a CODEOWNERS file to configure danger-mention HOT 1
- Missing blame information (Gitlab CI and docker)
- Add to danger.systems HOT 2
- GitLab support HOT 12
- Use GitHub request Reviewers feature HOT 1
- Something wrong with branch_for_base call (CircleCI) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from danger-mention.