Skip to content

Commit

Permalink
fix(publisher-github): replace special characters in the asset name
Browse files Browse the repository at this point in the history
ISSUES CLOSED: electron#1759
  • Loading branch information
mahnunchik committed Dec 18, 2020
1 parent 4824af6 commit 96cb015
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/publisher/github/src/PublisherGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
uploaded += 1;
updateSpinner();
};
const artifactName = path.basename(artifactPath);
// Based on https://developer.github.com/v3/repos/releases/#upload-a-release-asset and
// https://stackoverflow.com/questions/59081778/rules-for-special-characters-in-github-repository-name
const artifactName = path.basename(artifactPath)
.replace(/\s/g, '.')
.replace(/\.+/g, '.')
.replace(/^\./g, '')
.replace(/\.$/g, '')
.replace(/[^\w.-]/g, '-');
// eslint-disable-next-line max-len
if (release!.assets.find((asset: OctokitReleaseAsset) => asset.name === artifactName)) {
return done();
Expand All @@ -115,7 +122,7 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
'content-type': mime.lookup(artifactPath) || 'application/octet-stream',
'content-length': (await fs.stat(artifactPath)).size,
},
name: path.basename(artifactPath),
name: artifactName,
});
return done();
}));
Expand Down

0 comments on commit 96cb015

Please sign in to comment.