Skip to content

Commit

Permalink
feat: add username/token field in job submission
Browse files Browse the repository at this point in the history
  • Loading branch information
lynzrand committed Sep 26, 2021
1 parent 922f5cb commit 7e0e98b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1>{{ suite?.title }}</h1>
<div class="lblk">
<div id="job-submit">
<h2>提交评测</h2>
<div class="row col-container">
<div class="row col-container top">
<textbox
class="repo-input"
type="text"
Expand All @@ -38,6 +38,24 @@ <h2>提交评测</h2>
[(value)]="branch"
></textbox>
</div>
<div class="row col-container top">
<textbox
class="branch-input"
type="text"
placeholder=""
caption="用户名"
[icon]="userIcon"
[(value)]="username"
></textbox>
<textbox
class="branch-input"
type="password"
placeholder=""
caption="口令"
[icon]="passwordIcon"
[(value)]="password"
></textbox>
</div>
<div class="section" *ngIf="testGroups?.length > 1">
<h3>参与的测试组</h3>
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import RepoIcon from '@iconify/icons-mdi/git';
import DownArrowIcon from '@iconify/icons-mdi/chevron-down';
import UpArrowIcon from '@iconify/icons-mdi/chevron-up';
import TimeIcon from '@iconify/icons-carbon/timer';
import UserIcon from '@iconify/icons-carbon/user';
import PasswordIcon from '@iconify/icons-carbon/password';
import MemoryIcon from '@iconify/icons-carbon/chart-treemap';
import {
TestSuite,
Expand Down Expand Up @@ -39,6 +41,8 @@ import {
} from 'src/models/errors';
import { ApiService } from 'src/services/api_service';

const repoParser = /^https:\/\/(?:(.*?)(?::(.*?))?@)?(.+)$/;

@Component({
selector: 'app-test-suite-view',
templateUrl: './test-suite-view.component.html',
Expand Down Expand Up @@ -73,9 +77,13 @@ export class TestSuiteViewComponent implements OnInit, OnDestroy {
readonly upArrowIcon = UpArrowIcon;
readonly timeIcon = TimeIcon;
readonly memoryIcon = MemoryIcon;
readonly userIcon = UserIcon;
readonly passwordIcon = PasswordIcon;

repo: string = '';
branch: string = '';
username: string = '';
password: string = '';

repoMessage: string | undefined;
branchMessage: string | undefined;
Expand Down Expand Up @@ -205,7 +213,14 @@ export class TestSuiteViewComponent implements OnInit, OnDestroy {

private initSubmit() {
if (this.repo === '' && this.jobs && this.jobs.length > 0) {
this.repo = this.jobs[0].repo;
let repoParseResult = repoParser.exec(this.jobs[0].repo);
if (repoParseResult == null) {
this.repo = this.jobs[0].repo;
} else {
this.repo = 'https://' + repoParseResult[3];
this.username = repoParseResult[1] ?? '';
this.password = repoParseResult[2] ?? '';
}
this.branch = this.jobs[0].branch;
}
}
Expand Down Expand Up @@ -265,6 +280,19 @@ export class TestSuiteViewComponent implements OnInit, OnDestroy {
this.repoMessage = '请填写仓库地址';
return;
}
let repoParseResult = repoParser.exec(this.repo);
if (repoParseResult == null) {
this.repoMessage = '你提交的大概不是 HTTPS 仓库地址';
return;
}
let rawRepo = repoParseResult[3];
if (this.username) {
if (this.password) {
repo = `https://${this.username}:${this.password}@${rawRepo}`;
} else {
repo = `https://${this.username}@${rawRepo}`;
}
}

if (this.usingTestGroup.size === 0) {
this.repoMessage = '请至少选择一个测试';
Expand Down

0 comments on commit 7e0e98b

Please sign in to comment.