Skip to content

Commit

Permalink
draft: add semver-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
cocomeow committed Nov 5, 2021
1 parent 8552081 commit fc7fcfe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { request } from 'https://cdn.skypack.dev/@octokit/request';
import { semverRegex } from 'https://cdn.skypack.dev/semver-regex';
async function setACrossGitVersion() {
const content = await request('GET /repos/{owner}/{repo}/actions/artifacts', {
owner: 'Arktoria',
repo: 'ACross'
});
// TODO: match semver
const pkgNameStringArray = content.data.artifacts[0].name.split('-');
if (pkgNameStringArray.length !== 0) {
const pkgName = content.data.artifacts[0].name;
if (pkgName.length !== 0) {
const verDiv = document.getElementById('across-git-version');
const verElement = document.createElement('span');
const verStr = pkgNameStringArray[pkgNameStringArray.length - 1];
verElement.textContent = verStr;
verDiv === null || verDiv === void 0 ? void 0 : verDiv.appendChild(verElement);
const verStr = pkgName.match(semverRegex());
if (verStr !== null) {
verElement.textContent = verStr[0].toString();
verDiv === null || verDiv === void 0 ? void 0 : verDiv.appendChild(verElement);
}
}
}
setACrossGitVersion();
15 changes: 9 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { request } from 'https://cdn.skypack.dev/@octokit/request'
import { semverRegex } from 'https://cdn.skypack.dev/semver-regex'

async function setACrossGitVersion () {
const content = await request('GET /repos/{owner}/{repo}/actions/artifacts', {
owner: 'Arktoria',
repo: 'ACross'
})

// TODO: match semver
const pkgNameStringArray = content.data.artifacts[0].name.split('-')
const pkgName = content.data.artifacts[0].name

if (pkgNameStringArray.length !== 0) {
if (pkgName.length !== 0) {
const verDiv = document.getElementById('across-git-version')
const verElement = document.createElement('span')
const verStr = pkgNameStringArray[pkgNameStringArray.length - 1]
verElement.textContent = verStr
verDiv?.appendChild(verElement)
const verStr = pkgName.match(semverRegex())

if (verStr !== null) {
verElement.textContent = verStr[0].toString()
verDiv?.appendChild(verElement)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"@octokit/request": "^5.6.2",
"semver-regex": "^4.0.2",
"typescript": "^4.4.4"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions request.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
declare module 'https://cdn.skypack.dev/@octokit/request' {
export const request: import('@octokit/types').RequestInterface<object>
}

declare module 'https://cdn.skypack.dev/semver-regex' {
export const semverRegex: import('semver-regex').RequestInterface<object>
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,11 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

semver-regex@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-4.0.2.tgz#fd3124efe81647b33eb90a9de07cb72992424a02"
integrity sha512-xyuBZk1XYqQkB687hMQqrCP+J9bdJSjPpZwdmmNjyxKW1K3LDXxqxw91Egaqkh/yheBIVtKPt4/1eybKVdCx3g==

semver@^6.1.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
Expand Down

0 comments on commit fc7fcfe

Please sign in to comment.