Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use octokit + public repository API to generate projects data #57

Merged
merged 19 commits into from
Mar 3, 2022
Merged
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
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if I'm missing something, but prettier is not in this repo / in this branch. Did you mean to add prettier?

If so, can we try to keep the formatting consistent with what already exists? i.e., minimizing the number of changes introduced in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

This overrides the default prettier configs so that developers can use it and it can still stay consistent with what already exists. While it's not necessary, I think it can help remove some of the formatting conflicts that arose in other PRs.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha; to separate concerns, could we move this to another PR where we also add prettier? I think we removed a while back in another PR (#3 and #4), but it's probably a good idea to reintroduce.

7 changes: 3 additions & 4 deletions components/ELink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ function ELink ({link, children}: ELinkProps): JSX.Element {
};
return (
<Link href={link}>
<a {...linkProps}>
{children}
</a>
<a {...linkProps}>{children}</a>
</Link>
);

}

export default ELink;
export default ELink;
41 changes: 7 additions & 34 deletions components/GitHubEvent.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,22 @@
import moment from 'moment';
import React from 'react';
import { GitHubEvent } from '../util';
import ELink from './ELink';
import GitHubEventAction from './GitHubEventAction';

interface GitHubEvent {
id: string
type: string
actor: GitHubActor
repo: GitHubRepo
created_at: string
// TODO(#74): Change payload to GitHubEventPayloadType when types are accurate;
// being resolved in https://github.com/uclaacm/opensource/pull/57
// payload: GitHubEventPayloadType
// eslint-disable-next-line @typescript-eslint/no-explicit-any
payload: any
}

interface GitHubActor {
id: number
login: string
display_login?: string
gravatar_id: string
url: string
avatar_url: string
}

interface GitHubRepo {
id: number
name: string
url: string
}

function GitHubEvent(props: GitHubEvent): JSX.Element {
const {type, actor, repo, payload, created_at} = props;
function GitHubEventComponent(props: GitHubEvent): JSX.Element {
const { type, actor, repo, payload, created_at } = props;
const timePassed = moment(created_at).fromNow();

const userLink = !actor.login.includes('[bot]') ? <ELink link={`https://github.com/${actor.login}`}>{`@${actor.login}`}</ELink> : actor.login;
return (
<>
{/* <div className="card" style={{marginTop: "20px"}}> */}
{/* <div className="card-body"> */}
<div style = {{overflow: 'hidden'}}>
{userLink} <GitHubEventAction type={type} payload={payload}/>{' '}
<div style={{ overflow: 'hidden' }}>
{userLink} <GitHubEventAction type={type} payload={payload} />{' '}
<ELink link={`https://github.com/${repo.name}`}>{repo.name}</ELink>
<span style = {{float: 'right'}}>{timePassed}</span>
<span style={{ float: 'right' }}>{timePassed}</span>
</div>
<hr />
{/* </div> */}
Expand All @@ -52,4 +25,4 @@ function GitHubEvent(props: GitHubEvent): JSX.Element {
);
}

export default GitHubEvent;
export default GitHubEventComponent;
46 changes: 26 additions & 20 deletions components/GitHubEventAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,45 @@
// DISCLAIMER: Some types for GitHubEvent may not be exactly accurate.
// Take a look at https://docs.github.com/en/developers/webhooks-and-events/events/github-event-types
// for more accurate typing.
import type { CreateEvent, DeleteEvent, ForkEvent, IssueCommentEvent, IssuesEvent,
import type {
CreateEvent, DeleteEvent, ForkEvent, IssueCommentEvent, IssuesEvent,
MemberEvent, PullRequestEvent, PullRequestReviewCommentEvent, PullRequestReviewEvent,
PushEvent, PublicEvent, WatchEvent } from '@octokit/webhooks-types';
PushEvent, PublicEvent, WatchEvent,
} from '@octokit/webhooks-types';
import React from 'react';
import { GitHubEvent } from '../util';
import ELink from './ELink';

export type GitHubEventPayloadType =
| CreateEvent
| DeleteEvent
| ForkEvent
| IssueCommentEvent
| IssuesEvent
| MemberEvent
| PullRequestEvent
| PullRequestReviewCommentEvent
| PullRequestReviewEvent
| PushEvent
| PublicEvent
| WatchEvent;
| CreateEvent
| DeleteEvent
| ForkEvent
| IssueCommentEvent
| IssuesEvent
| MemberEvent
| PullRequestEvent
| PullRequestReviewCommentEvent
| PullRequestReviewEvent
| PushEvent
| PublicEvent
| WatchEvent;

interface GitHubEventActionProps {
type: string,
payload: GitHubEventPayloadType,
type: GitHubEvent['type'],
payload: GitHubEvent['payload'],
}

// TODO(mattxwang): this doesn't seem like the best way to do this ://
// returns a string of form: <verb> <location/type of action> <preposition>
function GitHubEventAction({type, payload}: GitHubEventActionProps): JSX.Element {
function GitHubEventAction({ type, payload }: GitHubEventActionProps): JSX.Element {
const unknown = <span>did a {type} on</span>;
switch(type){
switch (type) {
case 'CreateEvent':
case 'DeleteEvent': {
const payloadNarrowed = payload as DeleteEvent;
const target = payloadNarrowed.ref;
const targetType = payloadNarrowed.ref_type;
const action = type === 'CreateEvent'? 'created' : 'deleted';
const action = type === 'CreateEvent' ? 'created' : 'deleted';
if (!target) {
return <span>{action} the {targetType} </span>;
}
Expand Down Expand Up @@ -102,7 +105,10 @@ function GitHubEventAction({type, payload}: GitHubEventActionProps): JSX.Element
return <span>{action} <ELink link={prURL}>pull request #{prNum}</ELink> in</span>;
}
case 'PullRequestReviewCommentEvent': {
const payloadNarrowed = payload as PullRequestReviewCommentEvent;
//must do any since some fields are missing in the type declaration
// eslint-disable-next-line
const payloadNarrowed = payload as any as PullRequestReviewCommentEvent;

const action = payloadNarrowed.action;
const actionStr = action === 'created' ? 'commented' : action;
const prNum = payloadNarrowed.pull_request.number;
Expand Down
83 changes: 58 additions & 25 deletions components/ProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,108 @@
import Image from 'next/image';
import React from 'react';

import { Project } from '../util/';
import { Project, GitHubColors } from '../util/';
import ELink from './ELink';

interface ProjectCardProps {
project: Project
vertical?: boolean
preload?: boolean
project: Project;
vertical?: boolean;
preload?: boolean;
githubColors: GitHubColors
}

interface ProjectCardImageProps {
project: Project
preload: boolean
project: Project;
preload: boolean;
}

function ProjectCardImage({project, preload}: ProjectCardImageProps) {
function ProjectCardImage({ project, preload }: ProjectCardImageProps) {
const { image, alt, link } = project;
return (
return link ? (
<ELink link={link}>
<Image
src={image}
src={image ?? '/logo.png'}
alt={alt}
width="1000"
height="800"
height="1000"
layout="responsive"
priority={preload}
/>
</ELink>
) : (
<>
<Image
src={image}
alt={alt}
width="1000"
height="1000"
layout="responsive"
priority={preload}
/>
</>
);
}

function ProjectCardBody({ name, description, repo, link, lang, tech }: Project) {
interface ProjectCardBodyProps {
githubColors: GitHubColors,
project: Project
}

function ProjectCardBody(props: ProjectCardBodyProps) {
const {
name,
description,
repo,
link,
lang,
topics,
} = props.project;
return (
<div className="card-body">
<h3 className="mt-1">
<ELink link={link} >
{name}
</ELink>
{link ? <ELink link={link}>{name}</ELink> : name}
</h3>
<p>
<span className={`dev-language-badge lang-${lang}`}></span> {lang}
{tech && <span> • {tech.join(', ')}</span>}
<span
className="dev-language-badge"
style={{
backgroundColor: props.githubColors[lang]
? props.githubColors[lang].color
: 'black',
}}
></span>{' '}
{lang || 'Markdown'}
{topics.length > 0 && <span> • {topics.join(', ')}</span>}
</p>
<p>{description}</p>
<ELink link={repo}>
GitHub Repository
</ELink>
<ELink link={repo}>GitHub Repository</ELink>
</div>
);
}

// TODO(mattxwang): consider revisiting how this component works
// TODO(mattxwang): Mobile responsiveness (waiting on WestwoodCSS)
function ProjectCard({project, vertical = false, preload = false}: ProjectCardProps): JSX.Element {
function ProjectCard({
project,
vertical = false,
preload = false,
githubColors,
}: ProjectCardProps): JSX.Element {
if (vertical) {
return (
<div className="card">
<ProjectCardImage project={project} preload={preload}/>
<ProjectCardBody {...project}/>
<ProjectCardImage project={project} preload={preload} />
<ProjectCardBody project={project} githubColors={githubColors} />
</div>
);
}
return (
<div className="card">
<div className="row">
<div className="col-6">
<ProjectCardImage project={project} preload={preload}/>
<ProjectCardImage project={project} preload={preload} />
</div>
<div className="col-6">
<ProjectCardBody {...project}/>
<ProjectCardBody project={project} githubColors={githubColors} />
</div>
</div>
</div>
Expand Down
Loading