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

feat: pass tokenless value as branch override #1511

Merged
merged 11 commits into from
Aug 29, 2024

Conversation

joseph-sentry
Copy link
Contributor

instead of only passing the tokenless branch value as an environment variable we want to pass it as the branch value to the CLI

src/buildExec.ts Outdated
let token = core.getInput('token');
if (!token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
return Promise.resolve('');
return [false, context.payload.pull_request?.head.label];
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do let someVar = true and then set it to false here? it will make it more obvious what is being returned

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I believe this needs to be wrapped as a Promise still

src/buildExec.ts Outdated
const token = await getToken();
const [tokenAvailable, token] = await getToken();
if (!tokenAvailable) {
overrideBranch = token;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree with this, we should set overrideBranch = context.payload.pull_request?.head.label here instead. We run the risk of overloading our vars otherwise

instead of only passing the tokenless branch value as an environment
variable we want to pass it as the branch value to the CLI
src/buildExec.ts Outdated
let token = core.getInput('token');
if (!token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
return Promise.resolve('');
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

please write a test for this case

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.67%. Comparing base (2439dfc) to head (bc200a8).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/buildExec.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1511      +/-   ##
==========================================
+ Coverage   89.84%   93.67%   +3.82%     
==========================================
  Files           5        5              
  Lines         325      332       +7     
  Branches       78       78              
==========================================
+ Hits          292      311      +19     
+ Misses         33       19      -14     
- Partials        0        2       +2     
Flag Coverage Δ
demo 93.67% <92.85%> (+3.82%) ⬆️
macos-latest 93.67% <92.85%> (+3.82%) ⬆️
script 93.67% <92.85%> (+3.82%) ⬆️
ubuntu-latest 93.67% <92.85%> (+3.82%) ⬆️
version 93.67% <92.85%> (+3.82%) ⬆️
windows-latest 93.67% <92.85%> (+3.82%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/buildExec.ts Outdated Show resolved Hide resolved
src/buildExec.ts Outdated
@@ -45,12 +45,12 @@ const isPullRequestFromFork = (): boolean => {
return (baseLabel.split(':')[0] !== headLabel.split(':')[0]);
};

const getToken = async (): Promise<string> => {
const getToken = async (): Promise<string | null> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a comment on what to expect from null is needed here. Also, you are returning a Promise to null here but further down you are returning null as is

Copy link

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

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

is index.js codegenned by the typescript compiler? looks like we could add dist/index.js linguist-generated=true to .gitattributes to hide it from review. will it be automatically regenerated or is there a risk of updating the TS but not the index.js?

.github/workflows/main.yml Show resolved Hide resolved
src/buildExec.ts Outdated
Comment on lines 91 to 93
const token = await getToken();
if (!overrideBranch && token == null) {
overrideBranch = context.payload.pull_request?.head.label;

Choose a reason for hiding this comment

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

i think we should move the "are we a fork" stuff out of getToken() and into a new getOverrideBranch() function. whether we're a fork doesn't really factor into what the token is, just whether we want to set an override branch. but since the fork check happens inside of getToken(), we have to smuggle the result out of getToken() by saying null means "fork" and "" means "no fork" so that the override branch code can decide what to do. we should probably move the fork check to where it's really needed instead

const getOverrideBranch = async (token: string, context: Whatever): Promise<string | null> => {
  const overrideBranch = core.getInput("override_branch");
  if (!overrideBranch && !token && isPullRequestFromFork()) {
    return Promise.resolve(context.payload.pull_request?.head.label);
  } else {
    return Promise.resolve(overrideBranch);
  }
}

const token = await getToken();
const overrideBranch = getOverrideBranch(token, context);

with this change, getToken() really just gets the token, and getOverrideBranch() contains all of the logic about what the override branch should be, including the fork check

Copy link

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

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

looks good!

@trent-codecov trent-codecov removed the request for review from thomasrockhu-codecov August 28, 2024 21:51
@trent-codecov trent-codecov dismissed thomasrockhu-codecov’s stale review August 28, 2024 21:52

Changes addressed and Tom is OOO

@joseph-sentry joseph-sentry merged commit 4b21c32 into codecov:main Aug 29, 2024
10 checks passed
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.

3 participants