Skip to content

Commit

Permalink
Merge pull request #43 from 12f23eddde/fix-repo-update
Browse files Browse the repository at this point in the history
Fix critical issues
  • Loading branch information
hehao98 authored Oct 19, 2022
2 parents 576a5b3 + cb67200 commit 7ed0761
Show file tree
Hide file tree
Showing 18 changed files with 542 additions and 243 deletions.
51 changes: 0 additions & 51 deletions development/gfibot.dockerfile

This file was deleted.

352 changes: 286 additions & 66 deletions frontend/package-lock.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ export const updateRepoInfo = async (name: string, owner: string) => {
});
};

export const updateTags = async (name: string, owner: string) => {
const { githubLogin } = userInfo();
return await requestGFI<string>({
method: 'PUT',
url: '/api/repos/update/tags',
data: {
github_login: githubLogin,
name,
owner,
},
baseURL: getBaseURL(),
});
};

export const getRepoConfig = async (name: string, owner: string) => {
const { githubLogin } = userInfo();
return await requestGFI<RepoGFIConfig>({
Expand Down
35 changes: 18 additions & 17 deletions frontend/src/pages/main/mainHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import { GFIRootReducers } from '../../storage/configureStorage';
import { MainPageLangTagSelectedState } from '../../storage/reducers';

export type GFIRepoSearchingFilterType =
| 'None'
| 'Popularity'
| 'Median Issue Resolve Time'
| 'Newcomer Friendliness'
| 'GFIs';
export const GFI_REPO_FILTER_NONE: GFIRepoSearchingFilterType & string = 'None';
| 'Alphabetical'
| 'Number of Stars'
| 'Issue Resolution Time'
| '% of Issues Resolved by New Contributors'
| '# of Predicted Good First Issues';

export const GFI_REPO_FILTER_NONE: GFIRepoSearchingFilterType & string = 'Alphabetical';

export interface GFIMainPageHeader {
onSearch?: (s: string) => void;
Expand All @@ -33,14 +34,14 @@ export const GFIMainPageHeader = forwardRef((props: GFIMainPageHeader, ref) => {

const [search, setSearch] = useState<string | undefined>();
const [filterSelected, setFilterSelected] =
useState<GFIRepoSearchingFilterType>('None');
useState<GFIRepoSearchingFilterType>('Alphabetical');

const sortedBy: GFIRepoSearchingFilterType[] = [
'None',
'Popularity',
'GFIs',
'Median Issue Resolve Time',
'Newcomer Friendliness',
'Alphabetical',
'Number of Stars',
'Issue Resolution Time',
'% of Issues Resolved by New Contributors',
'# of Predicted Good First Issues',
];

const renderDropDownItem = (
Expand Down Expand Up @@ -71,12 +72,12 @@ export const GFIMainPageHeader = forwardRef((props: GFIMainPageHeader, ref) => {
});
};

const [tagArray, setTagArray] = useState<string[]>(['None']);
const [tagSelected, setTagSelected] = useState('None');
const [tagArray, setTagArray] = useState<string[]>(['All']);
const [tagSelected, setTagSelected] = useState('All');
useEffect(() => {
getLanguageTags().then((res) => {
if (res) {
setTagArray(['None', ...res]);
setTagArray(['All', ...res]);
}
});
}, []);
Expand Down Expand Up @@ -154,7 +155,7 @@ export const GFIMainPageHeader = forwardRef((props: GFIMainPageHeader, ref) => {
}}
>
<div className="flex-row align-center">
<div className="main-dropdown-tags">Sorted By</div>
<div className="main-dropdown-tags">Sort by</div>
<Dropdown
style={{
marginRight: '1rem',
Expand All @@ -178,7 +179,7 @@ export const GFIMainPageHeader = forwardRef((props: GFIMainPageHeader, ref) => {
</div>

<div className="flex-row align-center">
<div className="main-dropdown-tags">Tags</div>
<div className="main-dropdown-tags">Language</div>
<Dropdown>
<Dropdown.Toggle
variant="light"
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/main/mainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export function MainPage() {

useEffect(() => {
if (selectedTag || selectedFilter) {
fetchRepoInfoList(1, selectedTag, convertFilter(selectedFilter));
let _tag = selectedTag === "All" ? undefined : selectedTag;
fetchRepoInfoList(1, _tag, convertFilter(selectedFilter));
setPageIdx(1);
dispatch(
createMainPageLangTagSelectedAction({
Expand Down Expand Up @@ -338,7 +339,7 @@ export function MainPage() {
setSelectedTag(undefined);
dispatch(
createMainPageLangTagSelectedAction({
tagSelected: 'None',
tagSelected: 'All',
})
);
}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/pages/portal/GFIPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ function AddProjectComponent() {
const [showPopover, setShowPopover] = useState(false);

type FilterType = GFIRepoSearchingFilterType;
const [filterSelected, setFilterSelected] = useState<FilterType>('None');
const [filterSelected, setFilterSelected] = useState<FilterType>('Alphabetical');
const filters: FilterType[] = [
'None',
'Popularity',
'GFIs',
'Median Issue Resolve Time',
'Newcomer Friendliness',
'Alphabetical',
'Number of Stars',
'Issue Resolution Time',
'% of Issues Resolved by New Contributors',
'# of Predicted Good First Issues',
];

const onRepoHistoryClicked = (repoInfo: RepoBrief) => {
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/pages/portal/RepoSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getRepoConfig,
updateRepoConfig,
updateRepoInfo,
updateTags,
} from '../../api/api';
import type { RepoGFIConfig } from '../../model/api';
import { checkIsNumber } from '../../utils';
Expand Down Expand Up @@ -116,6 +117,12 @@ export function RepoSetting(props: RepoSettingPops) {
});
};

const updateGFITags = () => {
updateTags(repoInfo.name, repoInfo.owner).then((res) => {
setShowUpdateBanner(true);
});
};

return (
<div className="gfi-repo-setting-container flex-col flex-wrap align-items-stretch">
<div style={{ margin: '0 1rem' }}>
Expand Down Expand Up @@ -225,11 +232,20 @@ export function RepoSetting(props: RepoSettingPops) {
<Button
variant="outline-success"
size="sm"
onClick={() => {
updateGFITags();
}}
>
Tag GFIs
</Button>
<Button
variant="outline-warning"
size="sm"
onClick={() => {
updateGFIInfo();
}}
>
Update GFI Info
Force Update GFIs
</Button>
<Button
variant="outline-danger"
Expand Down
22 changes: 8 additions & 14 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,17 @@ export const checkHasUndefinedProperty = (obj: any) => {
return false;
};

const repoFilters = [
'popularity',
'median_issue_resolve_time',
'newcomer_friendly',
'gfis',
];

const filterNames = {
popularity: 'Popularity',
median_issue_resolve_time: 'Median Issue Resolve Time',
newcomer_friendly: 'Newcomer Friendliness',
gfis: 'GFIs',
'popularity': 'Number of Stars',
'median_issue_resolve_time': 'Issue Resolution Time',
'newcomer_friendly': '% of Issues Resolved by New Contributors',
'gfis': '# of Predicted Good First Issues',
};

const nameToFilter = Object.fromEntries(
Object.entries(filterNames).map(([k, v]) => [v, k])
);
const nameToFilter = Object.keys(filterNames).reduce((acc, cur) => {
acc[filterNames[cur]] = cur;
return acc;
}, {} as { [key: string]: string });

/** convert semantic filter names -> backend args */
export const convertFilter = (s: string): RepoSort | undefined => {
Expand Down
32 changes: 30 additions & 2 deletions gfibot/backend/background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from fastapi import HTTPException

from gfibot.collections import *
from gfibot.backend.scheduled_tasks import update_gfi_info, get_valid_tokens
from gfibot.backend.scheduled_tasks import (
update_gfi_info,
get_valid_tokens,
update_gfi_tags_and_comments,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -95,8 +99,9 @@ def add_repo_to_gfibot(owner: str, name: str, user: str) -> None:
)
user_record.save()
# add to repo_queries
q: Optional[GfiQueries] = GfiQueries.objects(Q(name=name) & Q(owner=owner)).first()
q: Optional[GfiQueries] = GfiQueries.objects(name=name, owner=owner).first()
if not q:
logger.info("Adding repo %s/%s to GFI-Bot", owner, name)
q = GfiQueries(
name=name,
owner=owner,
Expand All @@ -120,6 +125,7 @@ def add_repo_to_gfibot(owner: str, name: str, user: str) -> None:
task_id=f"{owner}-{name}-update",
interval=24 * 3600,
)

q.save()

token = (
Expand Down Expand Up @@ -174,6 +180,28 @@ def schedule_repo_update_now(
scheduler.add_job(update_gfi_info, id=job_id, args=[token, owner, name, send_email])


def schedule_tag_task_now(owner: str, name: str, send_email: bool = False):
"""
Run a temporary tag and comment job once
owner: Repo owner
name: Repo name
token: if None, random choice a token from the token pool
send_email: if True, send email to user after update
"""
from .server import get_scheduler

scheduler = get_scheduler()

job_id = f"{owner}-{name}-manual-tag"
if scheduler.get_job(job_id):
scheduler.remove_job(job_id)

# run once
scheduler.add_job(
update_gfi_tags_and_comments, id=job_id, args=[owner, name, send_email]
)


def remove_repo_from_gfibot(owner: str, name: str, user: str) -> None:
"""
Remove repo from GFI-Bot
Expand Down
4 changes: 3 additions & 1 deletion gfibot/backend/routes/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_oauth_app_login_url():
raise HTTPException(
status_code=404, detail="oauth record not found in database"
)
oauth_client_id = GithubTokens.objects().first().client_id
oauth_client_id = oauth_record.client_id
return GFIResponse(result=f"{GITHUB_LOGIN_URL}?client_id={oauth_client_id}")


Expand All @@ -159,6 +159,8 @@ def redirect_from_github(code: str, redirect_from: str = "github_app_login"):
"""
oauth_record: GithubTokens = GithubTokens.objects(
app_name="gfibot-githubapp"
if redirect_from == "github_app_login"
else "gfibot-webapp"
).first()
if not oauth_record:
raise HTTPException(
Expand Down
4 changes: 2 additions & 2 deletions gfibot/backend/routes/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_gfi_brief(
Prediction.objects(
Q(name=repo)
& Q(owner=owner)
& Q(probability__gte=gfi_thres)
# & Q(probability__gte=gfi_thres)
& Q(threshold=newcomer_thres)
& Q(state="open")
)
Expand Down Expand Up @@ -108,7 +108,7 @@ def get_gfi_num(
result=Prediction.objects(
Q(name=name)
& Q(owner=owner)
& Q(probability__gte=gfi_thres)
# & Q(probability__gte=gfi_thres)
& Q(threshold=newcomer_thres)
& Q(state="open")
).count()
Expand Down
Loading

0 comments on commit 7ed0761

Please sign in to comment.