Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/plugins/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -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, '-')
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
return name.toLowerCase().replace(/\s+/g, '-')
// Trim, replace whitespace with hyphens, remove disallowed chars, trim hyphens
return name
.trim()
.toLowerCase()
.replace(/\s+/g, '-') // Replace whitespace with hyphens
.replace(/[^a-z0-9-]/g, '') // Remove disallowed characters
.replace(/^-+|-+$/g, ''); // Remove leading/trailing hyphens

Copilot uses AI. Check for mistakes.
}
Comment on lines +55 to +57
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The slugify method lacks test coverage for team names with spaces. Given that this is the core fix for handling team names with spaces, tests should verify that names like "My Team Name" are correctly converted to "my-team-name". Add test cases covering single spaces, multiple consecutive spaces, and edge cases like leading/trailing spaces.

Copilot uses AI. Check for mistakes.

comparator (existing, attrs) {
return existing.slug === attrs.name.toLowerCase()
return existing.slug === this.slugify(attrs.name)
}

changed (existing, attrs) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The team_slug should use attrs.name instead of existing.name. The toParams method receives attrs from the config (which contains the team name as specified in the configuration) and existing from the GitHub API (which already has a slug property). Using existing.name here is inconsistent with how attrs.name is used elsewhere in this file (lines 60, 79), and it may not work correctly if the existing object structure differs from expectations. The consistent approach is to slugify the attrs.name parameter.

Suggested change
team_slug: this.slugify(existing.name),
team_slug: this.slugify(attrs.name),

Copilot uses AI. Check for mistakes.
owner: this.repo.owner,
repo: this.repo.repo,
permission: attrs.permission
Expand Down
Loading