Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/BaGet.UI/src/DisplayPackage/DisplayPackage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PackageType, InstallationInfo } from './InstallationInfo';
import LicenseInfo from './LicenseInfo';
import * as Registration from './Registration';
import SourceRepository from './SourceRepository';
import RepoDetails from './RepoDetails';
import { Versions, IPackageVersion } from './Versions';

import './DisplayPackage.css';
Expand Down Expand Up @@ -313,6 +314,8 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka

<p>{(!this.state.package.authors) ? 'Unknown' : this.state.package.authors}</p>
</div>

<RepoDetails url={this.state.package.projectUrl}/>

@loic-sharma loic-sharma Aug 25, 2020

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The projectUrl is the package's website, not necessarily it's source repository. Please use the repositoryUrl property instead:

[JsonPropertyName("repositoryUrl")]
public string RepositoryUrl { get; set; }

This property isn't part of the NuGet V3 protocol, but, it maps to the package's source repository metadata: https://docs.microsoft.com/en-us/nuget/reference/nuspec#repository

By the way, the repositoryUrl property on the TypeScript interface should be nullable. Could you fix that as part of your changes?

repositoryUrl?: string;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

</aside>
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions src/BaGet.UI/src/DisplayPackage/RepoDetails.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.project-stats > :last-child {
margin-left: 2rem;
}

.last-committed {
font-style: italic;
color: rgb(119, 119, 119);
margin-top: 1rem;
}
105 changes: 105 additions & 0 deletions src/BaGet.UI/src/DisplayPackage/RepoDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Icon } from 'office-ui-fabric-react/lib/Icon'
import { Link } from 'office-ui-fabric-react';
import * as React from 'react';

import './RepoDetails.css'

interface IRepoDetailsProps {
url: string;
}

interface IRepoDetailsState {
openIssues: number;
openPulls: number;
lastCommit: Date;
detailsFound: boolean;
}

class RepoDetails extends React.Component<IRepoDetailsProps, IRepoDetailsState> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why did you create a new component instead of updating the SourceRepository component?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I've finished this I might remove the heading tag and put it inside the SourceRepository component, this is a good point


private controller: AbortController;

constructor(props: IRepoDetailsProps) {
super(props);

this.controller = new AbortController();

this.state = {
openIssues: 0,
openPulls: 0,
lastCommit: new Date(),
detailsFound: false,
};
}

private getRepoOwnerAndName(repoUrl: string) {
const frags = repoUrl.split("/");
Comment thread
davidackroyd99 marked this conversation as resolved.
let retval = [];

for(var i = frags.length - 1; i > 0; i--) {
if(frags[i].length > 0) {
retval.push(frags[i])
}

if(retval.length == 2) {
break;
}
}

return retval.reverse();
}

private buildGitHubUrl(details: Array<string>) {
return `https://api.github.com/repos/${details[0]}/${details[1]}`;
}

public componentDidMount() {
if (this.props.url) {
const ownerAndName = this.getRepoOwnerAndName(this.props.url);

if(ownerAndName.length == 2) {
console.log(ownerAndName);
fetch(this.buildGitHubUrl(ownerAndName), {signal: this.controller.signal}).then(response => {
return response.json();
}).then(json => {
console.log(json);
this.setState({
detailsFound: true,
openIssues: json['open_issues'],
openPulls: 0,
lastCommit: new Date(json['pushed_at'])
});
// tslint:disable-next-line:no-console
}).catch((e) => console.log("Failed to load dependents.", e));
Comment thread
davidackroyd99 marked this conversation as resolved.
}

this.setState({
openIssues: 100,
openPulls: 23,
lastCommit: new Date(2020, 8, 21)
});
}
}

public render() {
if (!this.state.detailsFound) {
return null;
}

return (
<div>
<h2>Project Details</h2>

<div className="project-stats">
<Link href={this.props.url + "/issues"}><Icon iconName="Error" className="ms-Icon issues-icon" />{this.state.openIssues}</Link>
{/* <Link href={this.props.url + "/pulls"}><Icon iconName="BranchPullRequest" className="ms-Icon pulls-icon" />{this.state.openPulls}</Link> */}
</div>

<p className="last-committed">Last pushed on {this.state.lastCommit.toLocaleDateString()}</p>
</div>
);
}
}

export default RepoDetails;