-
Notifications
You must be signed in to change notification settings - Fork 189
fix: When team name contains spaces make sure it matches the team_slug #900
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
base: main-enterprise
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,9 +33,9 @@ module.exports = class Teams extends Diffable { | |||||
|
|
||||||
| this.log.debug('Removing all security manager teams since they should not be handled here') | ||||||
| this.log.debug(`Calling API to get security managers ${JSON.stringify(this.github.request.endpoint('GET /orgs/{org}/security-managers', | ||||||
| { | ||||||
| org: this.repo.owner | ||||||
| }))} `) | ||||||
| { | ||||||
| org: this.repo.owner | ||||||
| }))} `) | ||||||
| const resp = await this.github.paginate('GET /orgs/{org}/security-managers', | ||||||
| { org: this.repo.owner }) | ||||||
|
|
||||||
|
|
@@ -46,15 +46,18 @@ module.exports = class Teams extends Diffable { | |||||
| this.log.debug(`${this.repo.owner} Org does not have Security manager teams set up ${e}`) | ||||||
| } else { | ||||||
| this.log.error( | ||||||
| `Unexpected error when fetching for security manager teams org ${this.repo.owner} = ${e}` | ||||||
| `Unexpected error when fetching for security manager teams org ${this.repo.owner} = ${e}` | ||||||
| ) | ||||||
| } | ||||||
| return teams | ||||||
| } | ||||||
| } | ||||||
| slugify (name) { | ||||||
| return name.toLowerCase().replace(/\s+/g, '-') | ||||||
| } | ||||||
|
Comment on lines
+55
to
+57
|
||||||
|
|
||||||
| comparator (existing, attrs) { | ||||||
| return existing.slug === attrs.name.toLowerCase() | ||||||
| return existing.slug === this.slugify(attrs.name) | ||||||
| } | ||||||
|
|
||||||
| changed (existing, attrs) { | ||||||
|
|
@@ -73,7 +76,7 @@ module.exports = class Teams extends Diffable { | |||||
| add (attrs) { | ||||||
| let existing = { team_id: 1 } | ||||||
| this.log.debug(`Getting team with the parms ${JSON.stringify(attrs)}`) | ||||||
| return this.github.teams.getByName({ org: this.repo.owner, team_slug: attrs.name }).then(res => { | ||||||
| return this.github.teams.getByName({ org: this.repo.owner, team_slug: this.slugify(attrs.name) }).then(res => { | ||||||
| existing = res.data | ||||||
| this.log.debug(`adding team ${attrs.name} to repo ${this.repo.repo}`) | ||||||
| if (this.nop) { | ||||||
|
|
@@ -132,7 +135,7 @@ module.exports = class Teams extends Diffable { | |||||
| return { | ||||||
| team_id: existing.id, | ||||||
| org: this.repo.owner, | ||||||
| team_slug: attrs.name, | ||||||
| team_slug: this.slugify(existing.name), | ||||||
|
||||||
| team_slug: this.slugify(existing.name), | |
| team_slug: this.slugify(attrs.name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The slugify implementation doesn't handle leading or trailing spaces, which would result in slugs with leading or trailing hyphens (e.g., " Team Name " becomes "-team-name-"). Additionally, it doesn't handle other special characters that GitHub may not allow in team slugs. Consider trimming the input first and potentially handling other characters that need to be converted or removed.