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

Handle branch names containing hyphen separators #450

Merged

Conversation

tspencer244
Copy link
Contributor

This fixes an issue for me where I was not receiving anything for "alert-state" on Dependabot pull requests despite them being associated with a Dependabot alert.

I believe the issue is caused from how the directory name is derived from the git branch name, when a hyphen is used for the branch separator.

I think the Dependabot alert processing code appears to be looking for a match between the derived-from-branch package manifest file path and actual path on the Dependabot alert, so it never matches due to incorrectly derived base directory.

Before my changes, a branch name of dependabot-npm_and_yarn-nested-nested-fsevents-1.2.13 would say the directory is /fsevents.

My assumptions:

  • If a manifest file exists at /nested/nested/ecosystem.json, the branch name that uses hyphen separators would be dependabot-ecosystem-nested-nested-dependency-1.2.3

@tspencer244 tspencer244 requested a review from a team as a code owner October 12, 2023 05:42
@tspencer244 tspencer244 marked this pull request as draft October 12, 2023 05:44
@tspencer244 tspencer244 force-pushed the handle-branches-with-hyphens branch 2 times, most recently from cee26fc to 609e0ae Compare October 12, 2023 05:48
@tspencer244 tspencer244 marked this pull request as ready for review October 12, 2023 05:48
Copy link

@he-wowers he-wowers left a comment

Choose a reason for hiding this comment

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

makes sense to me

Comment on lines 52 to 56
// When a branch delimiter of "-" is used, we need to +1 to end of slice because there is always a hyphen
// between dependency name and version at the end of the branch name, regardless of configured branch separator.
// e.g. "fsevents-1.2.13".
const baseSliceEnd = delim === '-' ? 2 : 1
const dirname = `/${chunks.slice(2, -1 * (baseSliceEnd + (dependency['dependency-name'].match(/\//g) || []).length)).join('/') || ''}`
Copy link
Member

Choose a reason for hiding this comment

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

The test cases LGTM and this PR makes sense, but I think we should refactor dirname since baseSliceEnd adds some more complexity.

Suggested change
// When a branch delimiter of "-" is used, we need to +1 to end of slice because there is always a hyphen
// between dependency name and version at the end of the branch name, regardless of configured branch separator.
// e.g. "fsevents-1.2.13".
const baseSliceEnd = delim === '-' ? 2 : 1
const dirname = `/${chunks.slice(2, -1 * (baseSliceEnd + (dependency['dependency-name'].match(/\//g) || []).length)).join('/') || ''}`
// When a branch delimiter of "-" is used, we need to adjust for the hyphen
// between the dependency name and version at the end of the branch name
// e.g. "fsevents-1.2.13".
const adjustForDelim = delim === '-' ? 2 : 1
const numDirectorySegments = (dependency['dependency-name'].match(/\//g) || []).length + adjustForDelim
const dirname = `/${chunks.slice(2, -1 * numDirectorySegments).join('/') || ''}`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that calculating the directory name needs refactoring - will try to see if I can make it better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright I have tried to refactor it into something that is hopefully easier to follow - open to feedback

@@ -64,7 +68,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
newVersion: nextVersion,
compatScore: await scoreFn(dependency['dependency-name'], lastVersion, nextVersion, chunks[1]),
maintainerChanges: newMaintainer,
dependencyGroup: dependencyGroup,
dependencyGroup,
Copy link
Member

Choose a reason for hiding this comment

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

I think we have a weird linter rule that will tell you to do this? Let's ignore it for this PR

Suggested change
dependencyGroup,
dependencyGroup: dependencyGroup,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will undo this change then

Copy link
Member

Choose a reason for hiding this comment

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

I know I had asked you to change this, but I was wrong 😭
You had it right the first time. Could you change it back and remove the eslint exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ESLint rule has been fixed now

@@ -106,7 +106,7 @@ test('it supports multiple dependencies within a single fragment', async () => {
return Promise.resolve(0)
}

const updatedDependencies = await updateMetadata.parse(commitMessage, body, 'dependabot/nuget/api/main/coffee-rails', 'main', getAlert, getScore)
const updatedDependencies = await updateMetadata.parse(commitMessage, body, 'dependabot/nuget/api/main/coffee-rails/and/coffeescript', 'main', getAlert, getScore)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the branch name for this test was incorrect to begin with?

@@ -93,4 +93,5 @@ require('yargs')(hideBin(process.argv))
})
.demandCommand(1)
.help()
.strict()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this option makes the dry run script show an error if you forget to give the "check" argument

sliceEnd -= 1
}

// If there is more than 1 dependency name being updated, we assume 1 piece of the branch name will be "and".
Copy link
Member

Choose a reason for hiding this comment

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

good catch!

@Nishnha
Copy link
Member

Nishnha commented Nov 9, 2023

This LGTM. Before I merge could you undo the eslint exception I commented about in #450 (comment) and could you rebase this branch? It is currently out of date.

@aamagda
Copy link

aamagda commented Feb 27, 2024

Hi! Do you have a plan to merge this changes? Issue still actual

@tspencer244
Copy link
Contributor Author

This LGTM. Before I merge could you undo the eslint exception I commented about in #450 (comment) and could you rebase this branch? It is currently out of date.

I have undone the ESLint exception as well as rebased the pull request now

@tspencer244
Copy link
Contributor Author

Hi! Do you have a plan to merge this changes? Issue still actual

Sorry about this, I failed to notice that this pull request had been approved and was waiting for me to fix up some remaining issues.

I have fixed the remaining issues so hopefully there will be no further delay in getting this merged now.

Copy link
Member

@Nishnha Nishnha left a comment

Choose a reason for hiding this comment

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

Reapproving

@Nishnha Nishnha merged commit 5c7b450 into dependabot:main Apr 24, 2024
6 checks passed
github-actions bot pushed a commit to kairos-io/provider-kairos that referenced this pull request Apr 24, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[dependabot/fetch-metadata](https://togithub.com/dependabot/fetch-metadata)
| action | minor | `v2.0.0` -> `v2.1.0` |

---

### Release Notes

<details>
<summary>dependabot/fetch-metadata (dependabot/fetch-metadata)</summary>

###
[`v2.1.0`](https://togithub.com/dependabot/fetch-metadata/releases/tag/v2.1.0)

[Compare
Source](https://togithub.com/dependabot/fetch-metadata/compare/v2.0.0...v2.1.0)

#### What's Changed

- Relax `engine-strict=true` by
[@&#8203;jeffwidman](https://togithub.com/jeffwidman) in
[dependabot/fetch-metadata#510
- Handle branch names containing hyphen separators by
[@&#8203;tspencer244](https://togithub.com/tspencer244) in
[dependabot/fetch-metadata#450
- Switch to monthly release cadence by
[@&#8203;jeffwidman](https://togithub.com/jeffwidman) in
[dependabot/fetch-metadata#509
- v2.1.0 by
[@&#8203;fetch-metadata-action-automation](https://togithub.com/fetch-metadata-action-automation)
in
[dependabot/fetch-metadata#518

#### New Contributors

- [@&#8203;tspencer244](https://togithub.com/tspencer244) made their
first contribution in
[dependabot/fetch-metadata#450

**Full Changelog**:
dependabot/fetch-metadata@v2.0.0...v2.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 11pm every weekday,before 7am
every weekday,every weekend" in timezone Europe/Brussels, Automerge - At
any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/kairos-io/provider-kairos).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMTMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjMxMy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

5 participants