Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions changelog/issue-7776.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
audience: developers
level: patch
reference: issue 7776
---
Fixed schema to allow `.` in GitHub repository names.
4 changes: 2 additions & 2 deletions clients/client-go/tcgithub/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions clients/client-go/tcgithubevents/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions generated/references.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions services/github/schemas/constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# all common identifiers. It's not personal, it's just that without these
# limitation, the identifiers won't be useful as routing keys in RabbitMQ
# topic exchanges. Specifically, the length limitation and the fact that
# identifiers can't contain dots `.` is critical.
github-identifier-pattern: "^([a-zA-Z0-9-_%]*)$"
# GitHub service automatically sanitizes identifiers by replacing any dots `.` with another
# character, so dots are allowed but transformed.

github-identifier-pattern: "^([a-zA-Z0-9-_.%]*)$"
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please run yarn generate to update all autogenerated schemas as well? Or just let me know, I can run it

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 didn't spot any tests that would cover such checks. Would you be comfortable checking if you could add some new tests for repositories with dots?
Might be tricky to setup data for the tests though, I suggest starting with api_test.js

Thanks

Copy link
Author

Choose a reason for hiding this comment

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

Should I allow '%' ? Since ' . ' is later transformed into '%', allowing '%' could create ambiguity.

Copy link
Contributor

Choose a reason for hiding this comment

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

image looks like github is already strict with repository names, I wonder how '%' got there in the first place

Copy link
Author

Choose a reason for hiding this comment

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

The git_Identifier_pattern also allows whitespace-only strings. Is this something we should be concerned about?"

github-identifier-min-length: 1
github-identifier-max-length: 100
github-guid-pattern: "^[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}$"
Expand Down
75 changes: 75 additions & 0 deletions services/github/test/github_Identifier_Pattern_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import helper from './helper.js';
import assert from 'assert';
import fs from 'fs';
import yaml from 'js-yaml';

helper.secrets.mockSuite('github-identifier-pattern', [], function(mock, skipping) {
suiteSetup(async function() {
if (skipping()) return;
const constantsYaml = fs.readFileSync('../schemas/constants.yml', 'utf8');
const constants = yaml.load(constantsYaml);

this.githubPattern = new RegExp(constants['github-identifier-pattern']);
this.minLength = constants['github-identifier-min-length'];
this.maxLength = constants['github-identifier-max-length'];
});

function testLengthConstraints(id) {
assert.ok(id.length >= this.minLength, `"${id}" is shorter than min length`);
assert.ok(id.length <= this.maxLength, `"${id}" is longer than max length`);
}

test('valid GitHub identifiers', function() {
const validIdentifiers = [
'abc123',
'org-name',
'my_repo',
'repo123',
'ORG-Repo',
'abc.def',
'name_with_underscores',
'name%repo',
'percent%encoded',
'a',
'a'.repeat(100),
];

validIdentifiers.forEach(id => {
assert.ok(this.githubPattern.test(id), `Expected "${id}" to match github-identifier-pattern`);
testLengthConstraints.call(this, id);
});
});

test('invalid GitHub identifiers', function() {
const invalidIdentifiers = [
'with space',
'repo!',
'abc$123',
'@org/repo',
'org/repo',
'org//repo',
'repo#1',
'😀emoji',
'a'.repeat(101),
];

invalidIdentifiers.forEach(id => {
const matchesPattern = this.githubPattern.test(id);
const exceedsLength = id.length > this.maxLength;
assert.ok(!matchesPattern || exceedsLength, `Expected "${id}" to be invalid`);
});
});

test('edge cases for GitHub identifiers', function() {
const edgeCases = [
'a-b_c',
'repo-underscore_only_',
'repo-dash-only-',
'abc.def%ghi',
];
edgeCases.forEach(id => {
assert.ok(this.githubPattern.test(id), `Expected "${id}" to match github-identifier-pattern`);
testLengthConstraints.call(this, id);
});
});
});