Hacktoberfest의 끝
7958 단어 typescriptopensource
문제:
내가 별표 표시한 저장소에서 몇 가지 좋은 문제를 찾고 있었고 문제Update CreateEvent to deal with repository creation를 찾았습니다.
이것은 웹 사이트의 라이브 피드이며 누군가가 조직에서 새 저장소를 만들 때마다 메시지를 표시하지 못했습니다.
해결책 제시
프런트 엔드 구성 요소가 REST 끝점을 처리하는 방법을 살펴보겠습니다.
case 'CreateEvent':
case 'DeleteEvent': {
const target = payload?.ref;
const targetType = payload?.ref_type;
const action = type === 'CreateEvent'? 'created' : 'deleted';
if (!targetType || !target) {
return unknown;
}
return <span>{action} {targetType} <code>{target}</code> in</span>;
}
API가 반환한 데이터
{
"id": "18549674018",
"type": "CreateEvent",
"actor": {
"id": 65370631,
"login": "matthewcn56",
"display_login": "matthewcn56",
"gravatar_id": "",
"url": "https://api.github.com/users/matthewcn56",
"avatar_url": "https://avatars.githubusercontent.com/u/65370631?"
},
"repo": {
"id": 419984626,
"name": "uclaacm/status-check",
"url": "https://api.github.com/repos/uclaacm/status-check"
},
"payload": {
"ref": null,
"ref_type": "repository",
"master_branch": "main",
"description": "Check the health/status of ACM's various websites/deployments!",
"pusher_type": "user"
},
ref
는 사용자가 새 저장소를 생성할 때 null
이므로 코드는 기본 메시지 unknown
를 반환합니다. 따라서 조건을 추가하면 문제가 해결됩니다. if (!target) {
return <span>{action} the {targetType} </span>;
}
if (!targetType) {
return unknown;
}
반사
문제를 해결하기 어렵지는 않았지만 프로젝트의 워크플로를 알게 된 것이 더 중요하다는 것을 알았습니다. PR 테스트와 GitHub API를 통과하기 전에
husky
, pre-commit
후크에 대해 배우고 코드 린팅에 오류가 없는지 확인하는 방법을 배웠습니다.
Reference
이 문제에 관하여(Hacktoberfest의 끝), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/tuenguyen2911_67/the-end-of-hacktoberfest-3d40텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)