-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add endpoint to list substantive and non-substantive contributors in …
…a given repository
- Loading branch information
Showing
5 changed files
with
203 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
|
||
import React from "react"; | ||
import Spinner from "../components/spinner.jsx"; | ||
|
||
require("isomorphic-fetch"); | ||
let utils = require("./utils") | ||
, pp = utils.pathPrefix() | ||
; | ||
|
||
export default class ContributorsList extends React.Component { | ||
constructor (props) { | ||
super(props); | ||
this.state = { | ||
status: "loading" | ||
, owner: null | ||
, shortName: null | ||
, substantiveContributors: [] | ||
, nonSubstantiveContributors: [] | ||
}; | ||
} | ||
componentDidMount () { | ||
let owner = this.props.params.owner | ||
, shortName = this.props.params.shortName; | ||
fetch(pp + `api/repos/${owner}/${shortName}/contributors`, { credentials: "include" }) | ||
.then(utils.jsonHandler) | ||
.then((data) => { | ||
this.setState({ | ||
substantiveContributors: data.substantiveContributors | ||
, nonSubstantiveContributors: data.nonSubstantiveContributors | ||
, owner: owner | ||
, shortName: shortName | ||
, status: "ready" | ||
}); | ||
}) | ||
.catch(utils.catchHandler) | ||
; | ||
} | ||
|
||
render () { | ||
let st = this.state | ||
, content | ||
, repositoryLink = "" | ||
, substantiveKeys | ||
, nonSubstantiveKeys | ||
; | ||
if (st.status === "loading") { | ||
content = <Spinner prefix={pp}/>; | ||
} | ||
else if (st.status === "ready") { | ||
repositoryLink = <a href={`https://github.com/${st.owner}/${st.shortName}`}>{`${st.owner}/${st.shortName}`}</a>; | ||
substantiveKeys = Object.keys(st.substantiveContributors); | ||
nonSubstantiveKeys = Object.keys(st.nonSubstantiveContributors); | ||
content = ( | ||
<div> | ||
{[substantiveKeys, nonSubstantiveKeys].map((type) => { | ||
if (type.length > 0) { | ||
return ( | ||
<div> | ||
<h3>{type === substantiveKeys ? "Substantive" : "Non-substantive"} contributions</h3> | ||
<table className={`${type}-contributors-list`}> | ||
<thead> | ||
<tr> | ||
<th>Contributor</th> | ||
<th>PR</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
type.map((i) => { | ||
return <tr key={(type === substantiveKeys ? st.substantiveContributors : st.nonSubstantiveContributors)[i].name}> | ||
<td>{(type === substantiveKeys ? st.substantiveContributors : st.nonSubstantiveContributors)[i].name}</td> | ||
<td> | ||
<ul> | ||
{(type === substantiveKeys ? st.substantiveContributors : st.nonSubstantiveContributors)[i].prs.map((pr) => { | ||
return <li key={pr}><a href={`${pp}pr/id/${st.owner}/${st.shortName}/${pr}`}>PR #{pr}</a></li> | ||
})} | ||
</ul> | ||
</td> | ||
</tr> | ||
}) | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
} | ||
} | ||
)} | ||
</div> | ||
// {substantiveKeys.length > 0 && ( | ||
// <div> | ||
// <h3>Substantive contributions</h3> | ||
// <table className="substantive-contributors-list"> | ||
// <thead> | ||
// <tr> | ||
// <th>Contributor</th> | ||
// <th>PR</th> | ||
// </tr> | ||
// </thead> | ||
// <tbody> | ||
// { | ||
// substantiveKeys.map((i) => { | ||
// return <tr key={st.substantiveContributors[i].name}> | ||
// <td>{st.substantiveContributors[i].name}</td> | ||
// <td> | ||
// <ul> | ||
// {st.substantiveContributors[i].prs.map((pr) => { | ||
// return <li key={pr}><a href={`${pp}pr/id/${st.owner}/${st.shortName}/${pr}`}>PR #{pr}</a></li> | ||
// })} | ||
// </ul> | ||
// </td> | ||
// </tr> | ||
// }) | ||
// } | ||
// </tbody> | ||
// </table> | ||
// </div> | ||
// )} | ||
// {nonSubstantiveKeys.length > 0 && ( | ||
// <div> | ||
// <h3>Non-substantive contributions</h3> | ||
// <table className="non-substantive-contributors-list"> | ||
// <thead> | ||
// <tr> | ||
// <th>Contributor</th> | ||
// <th>PR</th> | ||
// </tr> | ||
// </thead> | ||
// <tbody> | ||
// { | ||
// nonSubstantiveKeys.map((i) => { | ||
// return <tr key={st.nonSubstantiveContributors[i].name}> | ||
// <td>{st.nonSubstantiveContributors[i].name}</td> | ||
// <td> | ||
// <ul> | ||
// {st.nonSubstantiveContributors[i].prs.map((pr) => { | ||
// return <li key={pr}><a href={`${pp}pr/id/${st.owner}/${st.shortName}/${pr}`}>PR #{pr}</a></li> | ||
// })} | ||
// </ul> | ||
// </td> | ||
// </tr> | ||
// }) | ||
// } | ||
// </tbody> | ||
// </table> | ||
// </div> | ||
// )} | ||
// </div> | ||
// ); | ||
)} | ||
|
||
return <div className="primary-app"> | ||
<h2>List of contributors on {repositoryLink}</h2> | ||
{content} | ||
</div> | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters