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

Add repository parameter #19

Merged
merged 5 commits into from
Nov 16, 2021
Merged

Conversation

TravisEz13
Copy link
Contributor

@TravisEz13 TravisEz13 commented Nov 13, 2021

Fixes #18

@TravisEz13
Copy link
Contributor Author

not sure if I should include the changes that showed up in dist... I can drop the commit if you want.

@juliangruber
Copy link
Owner

not sure if I should include the changes that showed up in dist... I can drop the commit if you want.

yeah could you please drop it? The build script will take care of updating it when I cut a new release

index.js Outdated Show resolved Hide resolved
@TravisEz13
Copy link
Contributor Author

Okay, I removed the dist changes.
I also updated repo to be an object.

index.js Outdated
Comment on lines 9 to 22
const repo = core.getInput('repo')

var repoValue
if (!repo) {
repoValue = context.repo
} else {
const [owner, repo] = repo.split('/')
repoValue = {owner, repo}
}

const octokit = new GitHub(token)

await octokit.pulls.createReview({
...context.repo,
...repoValue,
Copy link
Owner

Choose a reason for hiding this comment

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

Hey, out of respect for your time and since I saw a few areas to improve, let me suggest an implementation here:

  const repoString = core.getInput('repo')

  let repoObject
  if (repoString) {
    const [owner, repo] = repoString.split('/')
    repoObject = { owner, repo }
  } else {
    repoObject = context.repo
  }

  const octokit = new GitHub(token)

  await octokit.pulls.createReview({
    ...repoObject,

Main changes:

  • use let instead of var, which is more explicit
  • get around the awkward repo naming (it's not our fault "repo" can mean repository name or "owner/repo" string) by being explicit about it
  • conditionals read easier if the positive condition comes first

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I don't program in JavaScript except for very occasional contributions like this.

I had to read about let vs var. let is more scoped than var but just as explicit. It is scoped to the exact block not just the function you are in. scoping is good for many reasons.

Copy link
Owner

Choose a reason for hiding this comment

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

if you're interested, let is more explicit than var in that you expect the value of let to change, while if you have an unchangable value you use const. var is used for both purposes

@juliangruber juliangruber merged commit 9f36191 into juliangruber:master Nov 16, 2021
@juliangruber
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Approve a pull request in a different repository
3 participants