sepandhaghighi / sepandhaghighi/githubp

[Task]: Refactor `getTargetUrl()` to handle GitHub path conversion

Open Beginner friendly
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactoring
Dominant language
JavaScript
Stars
15
Forks
0
Avg merge
1d 18h
Merged PRs (30d)
2

Description

Describe the feature you want to add

Refactor the GitHub path conversion logic so that getTargetUrl() becomes the single reusable function responsible for validating the parsed GitHub username and generating the corresponding GitHub Pages URL.

Describe your proposed solution

Update getTargetUrl() so that it validates the username before generating the target URL.

For example:

function getTargetUrl(username, repositoryName) {
  if (!username || !isValidUserName(username)) {
    return null;
  }
  return repositoryName
    ? `https://${username}.${CONFIG.URLS.PAGES}/${repositoryName}`
    : `https://${username}.${CONFIG.URLS.PAGES}`;
}

Then simplify submitPath() to use the return value from getTargetUrl():

function submitPath(path) {
  const { username, repositoryName } = parseGithubPath(path);
  const targetUrl = getTargetUrl(username, repositoryName);

  if (!targetUrl) {
    return false;
  }

  saveRecent(targetUrl);
  redirectToGithubPages(targetUrl);
  return true;
}

This keeps URL generation and username validation together, without introducing another helper function solely for obtaining the target URL.

Describe alternatives you've considered, if relevant

No response

Additional context

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate getTargetUrl() and submitPath(), then read the existing parseGithubPath() and isValidUserName() logic they use. Centralize username validation and GitHub Pages URL generation in getTargetUrl(), simplify submitPath() to use its result, and verify valid usernames, repository paths, and invalid or missing usernames retain the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.