Hacktoberfest의 끝

7958 단어 typescriptopensource
마지막으로 내 4th pull request이 병합되었습니다.

문제:



내가 별표 표시한 저장소에서 몇 가지 좋은 문제를 찾고 있었고 문제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 후크에 대해 배우고 코드 린팅에 오류가 없는지 확인하는 방법을 배웠습니다.

좋은 웹페이지 즐겨찾기