Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Jan 6, 2019
0 parents commit 6736d7c
Show file tree
Hide file tree
Showing 129 changed files with 7,001 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .autod.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

module.exports = {
write: true,
prefix: '^',
plugin: 'autod-egg',
test: [
'test',
'benchmark',
],
dep: [
'egg',
'egg-scripts',
],
devdep: [
'egg-ci',
'egg-bin',
'egg-mock',
'autod',
'autod-egg',
'eslint',
'eslint-config-egg',
'webstorm-disable-index',
],
exclude: [
'./test/fixtures',
'./dist',
],
};

15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
test
run
docker
logs
.idea
.npmignore
.travis.yml
.gitignore
.git
.eslintrc
.eslintignore
.autod.conf.js
*.md
*.yml
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "eslint-config-egg",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
}
}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.nyc_output
.idea/
.vscode/
run/
.DS_Store
*.sw*
*.un~
9 changes: 9 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const path = require('path');

module.exports = {
config: path.join(__dirname, 'database/config.js'),
'migrations-path': path.join(__dirname, 'database/migrations'),
'seeders-path': path.join(__dirname, 'database/seeders'),
};
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sudo: false

language: node_js

services:
- docker

node_js:
- '8'

before_install:
- docker pull macacajs/reliable-mysql
- docker run --rm --name reliable-mysql -p 13306:3306 -d macacajs/reliable-mysql
- docker ps -a

install:
- npm i npminstall && npminstall

script:
- MYSQL_PORT=13306 npm run ci

after_script:
- npminstall codecov && codecov
60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM centos:centos7

RUN yum -y install curl \
&& mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \
&& curl http://mirrors.163.com/.help/CentOS7-Base-163.repo -o /etc/yum.repos.d/CentOS7-Base-163.repo \
&& yum clean all \
&& yum makecache \
&& yum install -y make \
bzip2 \
gcc-c++ \
ca-certificates \
xorg-x11-server-Xvfb \
gtk2 \
vim \
git \
gtk2-devel \
libXScrnSaver \
GConf2 \
libXtst.i686 \
alsa-lib-devel \
libXScrnSaver* \
epel-release \
libappindicator-gtk3 \
libnss3.so \
glibc-common \
xorg-x11-fonts-Type1 \
wqy-microhei-fonts \
wqy-zenhei-fonts \
thai-scalable-garuda-fonts \
cjkuni-ukai-fonts \
cjkuni-uming-fonts

# Variable Layer: Node.js etc.
ENV NODE_VERSION=8.12.0 \
NODE_REGISTRY=https://npm.taobao.org/mirrors/node \
CHROMEDRIVER_CDNURL=http://npm.taobao.org/mirrors/chromedriver/ \
ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/ \
DISPLAY=':99.0' \
NODE_IN_DOCKER=1

RUN curl -SLO "$NODE_REGISTRY/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" \
&& tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 \
&& rm "node-v$NODE_VERSION-linux-x64.tar.gz"

COPY . /root/reliable-web

WORKDIR /root/reliable-web

ENV MYSQL_HOST=mysql-host

RUN npm install --production --verbose && ln -s /root/logs .

HEALTHCHECK --interval=10s --retries=6 \
CMD wget -O /dev/null localhost:9900 || echo 1

ENTRYPOINT ["./entrypoint.sh"]

EXPOSE 9900

CMD ["npm", "start"]
22 changes: 22 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT LICENSE

Copyright (c) 2018 Alibaba Group Holding Limited and other contributors.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Reliable

[中文版](README.zh-CN.md)

<p align="center">
<a href="//macacajs.github.io/reliable">
<img
alt="Macaca"
src="https://macacajs.github.io/reliable-logo/svg/logo-2.svg"
width="200"
/>
</a>
</p>

---

[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![node version][node-image]][node-url]
[![docker pull][docker-pull-image]][docker-url]
[![docker layers][docker-layers-image]][docker-url]
[![docker-size][docker-size-image]][docker-url]

[travis-image]: https://img.shields.io/travis/macacajs/reliable/master.svg?style=flat-square&logo=travis
[travis-url]: https://travis-ci.org/macacajs/reliable
[codecov-image]: https://img.shields.io/codecov/c/github/macacajs/reliable/master.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/macacajs/reliable
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[docker-pull-image]: https://img.shields.io/docker/pulls/macacajs/reliable-web.svg?style=flat-square&logo=dockbit
[docker-layers-image]: https://img.shields.io/microbadger/layers/macacajs/reliable-web.svg?style=flat-square&logo=dockbit
[docker-size-image]: https://img.shields.io/microbadger/image-size/macacajs/reliable-web.svg?style=flat-square&logo=dockbit
[docker-url]: https://hub.docker.com/r/macacajs/reliable-web/

> Testing management suite with continuous delivery support.
## Docs

- [CLI Usage](//github.com/macacajs/reliable-cli)
- [Development](./docker/reliable-web#development)

## License

The MIT License (MIT)
10 changes: 10 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Reliable

---

> 持续交付测试套件
## 文档

- [命令行客户端](//github.com/macacajs/reliable-cli)
- [开发 Reliable](./docker/reliable-web#development)
22 changes: 22 additions & 0 deletions app/common/error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

// key: error code
// value: error details
// value.message: default error message
module.exports = new Map([
[
'ERR_RELIABLE_INTERNAL_SERVER_ERROR', {
message: 'Internal server error.',
},
],
[
'ERR_RELIABLE_INVALID_PARAM_ERROR', {
message: 'Invalid parameters.',
},
],
[
'ERR_RELIABLE_BUILD_RECORD_NOT_FOUND', {
message: 'Build record not found.',
},
]
]);
99 changes: 99 additions & 0 deletions app/common/snsAuthorize/dingtalkAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict';

const querystring = require('querystring');
const debug = require('debug')('reliable:common:dingtalkAuth');

module.exports = class DingtalkAuth {
constructor({ ctx, appid, appsecret }) {
this.ctx = ctx;
this.appid = appid;
this.appsecret = appsecret;
}

async getAuthData({ tmpAuthCode }) {
const accessTokenInfo = await this._getAccessToken();
debug(accessTokenInfo);
const persistentCodeInfo = await this._getPersistentCode({
accessToken: accessTokenInfo.access_token,
tmpAuthCode,
});
debug(persistentCodeInfo);
const snsTokenInfo = await this._getSnsToken({
accessToken: accessTokenInfo.access_token,
openid: persistentCodeInfo.openid,
persistentCode: persistentCodeInfo.persistent_code,
});
debug(snsTokenInfo);
const userInfo = await this._getUserInfo({
snsToken: snsTokenInfo.sns_token,
});
debug(userInfo);
const {
nick,
unionid,
openid,
} = userInfo.user_info || {};
return {
nick,
unionid,
openid,
};
}

async _getAccessToken() {
const query = querystring.stringify({
appid: this.appid,
appsecret: this.appsecret,
});
debug(query);
const requestAccessToken = await this.ctx.curl(`https://oapi.dingtalk.com/sns/gettoken?${query}`, {
dataType: 'json',
});
return requestAccessToken.data;
}

async _getPersistentCode({ accessToken, tmpAuthCode }) {
const query = querystring.stringify({
access_token: accessToken,
});
debug(query);
const requestPersistentCode = await this.ctx.curl(`https://oapi.dingtalk.com/sns/get_persistent_code?${query}`, {
method: 'POST',
dataType: 'json',
contentType: 'json',
data: {
tmp_auth_code: tmpAuthCode,
},
});
return requestPersistentCode.data;
}

async _getSnsToken({ accessToken, openid, persistentCode }) {
const query = querystring.stringify({
access_token: accessToken,
});
debug(query);
const requestSnsToken = await this.ctx.curl(`https://oapi.dingtalk.com/sns/get_sns_token?${query}`, {
method: 'POST',
dataType: 'json',
contentType: 'json',
data: {
openid,
persistent_code: persistentCode,
},
});
return requestSnsToken.data;
}

async _getUserInfo({ snsToken }) {
const query = querystring.stringify({
sns_token: snsToken,
});
debug(query);
const requestUserInfo = await this.ctx.curl(`https://oapi.dingtalk.com/sns/getuserinfo?${query}`, {
dataType: 'json',
contentType: 'json',
});
return requestUserInfo.data;
}
};
6 changes: 6 additions & 0 deletions app/constants/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
BUILD_STATE_INIT: 'INIT',
BUILD_STATE_SUCCESS: 'SUCCESS',
};
Loading

0 comments on commit 6736d7c

Please sign in to comment.