Skip to content

Commit 4a9ac98

Browse files
update: Removed depreciated parameter
1 parent 50a12b1 commit 4a9ac98

14 files changed

+948
-174
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ typings/
9696
.serverless
9797

9898
##Apple
99-
.DS_store
99+
.DS_store
100+
101+
.vscode

CODE_OF_CONDUCT.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
education, socio-economic status, nationality, personal appearance, race,
10+
religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+

CONTRIBUTING.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Contributing
2+
3+
[fork]: /fork
4+
[pr]: /compare
5+
[style]: https://standardjs.com/
6+
[code-of-conduct]: CODE_OF_CONDUCT.md
7+
8+
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
9+
10+
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
11+
12+
## Issues and PRs
13+
14+
If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them.
15+
16+
We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR.
17+
18+
## Submitting a pull request
19+
20+
1. [Fork][fork] and clone the repository.
21+
1. Configure and install the dependencies: `npm install`.
22+
1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so there's no need to lint separately.
23+
1. Create a new branch: `git checkout -b my-branch-name`.
24+
1. Make your change, add tests, and make sure the tests still pass.
25+
1. Push to your fork and [submit a pull request][pr].
26+
1. Pat your self on the back and wait for your pull request to be reviewed and merged.
27+
28+
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
29+
30+
- Follow the [style guide][style] which is using standard. Any linting errors should be shown when running `npm test`.
31+
- Write and update tests.
32+
- Keep your changes as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
33+
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
34+
35+
Work in Progress pull requests are also welcome to get feedback early on, or if there is something blocked you.
36+
37+
## Resources
38+
39+
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
40+
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
41+
- [GitHub Help](https://help.github.com)

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Commit Message Lint
32
Github app to validate commit message and pull request title on a pull request
43

@@ -39,9 +38,13 @@ Step 3. Create `.env` file in the root directory and set the following environme
3938
REGEX_CONFIG_FILE_NAME - config file which contains repo config, keep it as config.yml
4039
GITHUB_BASE_PATH - Github API path, keep it as https://api.github.com
4140
```
41+
Note : Take values of APP_ID, WEBHOOK_PROXY_URL, WEBHOOK_SECRET, PRIVATE_KEY from https://github.com/settings/apps/commit-message-lint
42+
4243
Step 4. Run `npm start` to start the application
4344

4445
## Contributors
4546
[Anshul Soni](https://www.linkedin.com/in/anshul-soni-3903a2101/)
4647

47-
[Sumit Singhal](https://www.linkedin.com/in/s-singhal)
48+
[Sumit Singhal](https://www.linkedin.com/in/s-singhal)
49+
50+
[Vikas Patidar](https://www.linkedin.com/in/vikas-patidar-0106/)

app.yml

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# This is a GitHub App Manifest. These settings will be used by default when
2+
# initially configuring your GitHub App.
3+
#
4+
# NOTE: changing this file will not update your GitHub App settings.
5+
# You must visit github.com/settings/apps/your-app-name to edit them.
6+
#
7+
# Read more about configuring your GitHub App:
8+
# https://probot.github.io/docs/development/#configuring-a-github-app
9+
#
10+
# Read more about GitHub App Manifests:
11+
# https://developer.github.com/apps/building-github-apps/creating-github-apps-from-a-manifest/
12+
13+
# The list of events the GitHub App subscribes to.
14+
# Uncomment the event names below to enable them.
15+
default_events:
16+
- check_run
17+
- check_suite
18+
# - commit_comment
19+
# - create
20+
# - delete
21+
- deployment
22+
- deployment_status
23+
# - fork
24+
# - gollum
25+
# - issue_comment
26+
# - issues
27+
# - label
28+
# - milestone
29+
# - member
30+
# - membership
31+
# - org_block
32+
# - organization
33+
# - page_build
34+
# - project
35+
# - project_card
36+
# - project_column
37+
# - public
38+
- pull_request
39+
# - pull_request_review
40+
# - pull_request_review_comment
41+
# - push
42+
# - release
43+
# - repository
44+
# - repository_import
45+
# - status
46+
# - team
47+
# - team_add
48+
# - watch
49+
50+
# The set of permissions needed by the GitHub App. The format of the object uses
51+
# the permission name for the key (for example, issues) and the access type for
52+
# the value (for example, write).
53+
# Valid values are `read`, `write`, and `none`
54+
default_permissions:
55+
# Repository creation, deletion, settings, teams, and collaborators.
56+
# https://developer.github.com/v3/apps/permissions/#permission-on-administration
57+
# administration: read
58+
59+
# Checks on code.
60+
# https://developer.github.com/v3/apps/permissions/#permission-on-checks
61+
# checks: read
62+
63+
# Repository contents, commits, branches, downloads, releases, and merges.
64+
# https://developer.github.com/v3/apps/permissions/#permission-on-contents
65+
# contents: read
66+
67+
# Deployments and deployment statuses.
68+
# https://developer.github.com/v3/apps/permissions/#permission-on-deployments
69+
# deployments: read
70+
71+
# Issues and related comments, assignees, labels, and milestones.
72+
# https://developer.github.com/v3/apps/permissions/#permission-on-issues
73+
# issues: write
74+
75+
# Search repositories, list collaborators, and access repository metadata.
76+
# https://developer.github.com/v3/apps/permissions/#metadata-permissions
77+
metadata: read
78+
79+
# Retrieve Pages statuses, configuration, and builds, as well as create new builds.
80+
# https://developer.github.com/v3/apps/permissions/#permission-on-pages
81+
# pages: read
82+
83+
# Pull requests and related comments, assignees, labels, milestones, and merges.
84+
# https://developer.github.com/v3/apps/permissions/#permission-on-pull-requests
85+
pull_requests: read
86+
87+
# Manage the post-receive hooks for a repository.
88+
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-hooks
89+
# repository_hooks: read
90+
91+
# Manage repository projects, columns, and cards.
92+
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-projects
93+
# repository_projects: read
94+
95+
# Retrieve security vulnerability alerts.
96+
# https://developer.github.com/v4/object/repositoryvulnerabilityalert/
97+
# vulnerability_alerts: read
98+
99+
# Commit statuses.
100+
# https://developer.github.com/v3/apps/permissions/#permission-on-statuses
101+
# statuses: read
102+
103+
# Organization members and teams.
104+
# https://developer.github.com/v3/apps/permissions/#permission-on-members
105+
# members: read
106+
107+
# View and manage users blocked by the organization.
108+
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-user-blocking
109+
# organization_user_blocking: read
110+
111+
# Manage organization projects, columns, and cards.
112+
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-projects
113+
# organization_projects: read
114+
115+
# Manage team discussions and related comments.
116+
# https://developer.github.com/v3/apps/permissions/#permission-on-team-discussions
117+
# team_discussions: read
118+
119+
# Manage the post-receive hooks for an organization.
120+
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-hooks
121+
# organization_hooks: read
122+
123+
# Get notified of, and update, content references.
124+
# https://developer.github.com/v3/apps/permissions/
125+
# organization_administration: read
126+
127+
128+
# The name of the GitHub App. Defaults to the name specified in package.json
129+
# name: My Probot App
130+
131+
# The homepage of your GitHub App.
132+
# url: https://example.com/
133+
134+
# A description of the GitHub App.
135+
# description: A description of my awesome app
136+
137+
# Set to true when your GitHub App is available to the public or false when it is only accessible to the owner of the app.
138+
Default: true
139+
# public: false

constants.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ module.exports = {
3939
PULL_REQUEST_OPEN: 'pull_request.opened',
4040
CHECK_RUN_REREQUESTED: 'check_run.rerequested',
4141
CHECK_SUITE_REREQUESTED: 'check_suite.rerequested',
42-
CHECK_SUITE_REQUESTED: 'check_suite.requested'
43-
}
42+
CHECK_SUITE_REQUESTED: 'check_suite.requested',
43+
MARKETPLACE_PURCHASE: 'marketplace_purchase',
44+
CHECK_SUITE: 'check_suite'
45+
},
46+
OAUTH_ENDPOINT: 'https://github.com/login/oauth'
4447
};

controllers/marketplace.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Packages
3+
*/
4+
const rp = require('request-promise');
5+
/**
6+
* Constants
7+
*/
8+
const { OAUTH_ENDPOINT } = require('../constants');
9+
10+
/**
11+
* Controllers
12+
*/
13+
module.exports.marketplaceEventHandlers = async (req, res) => {
14+
try {
15+
let body = req.body;
16+
if(body.action && eventHandlers[body.action]) {
17+
await eventHandlers[body.action](req, res, body);
18+
}
19+
} catch (error) {
20+
console.log(error);
21+
}
22+
};
23+
24+
module.exports.getAccessToken = async (req, res) => {
25+
try {
26+
const query = req.query;
27+
const getAccessToken = `${OAUTH_ENDPOINT}/access_token?client_id=${process.env.CLIENT_ID}&client_secret=${process.env.CLIENT_SECRET}&code=${query.code}&redirect_uri=${process.env.REDIRECT_URI}&state=${query.STATE}`;
28+
let accessToken = await rp(getAccessToken);
29+
res.json(accessToken);
30+
} catch (error) {
31+
console.log(error);
32+
}
33+
};
34+
35+
/**
36+
* Market place event handlers
37+
* TODO: Move to separate file after finalizing structure
38+
*/
39+
let eventHandlers = {
40+
purchased: async (req, res, eventData) => {
41+
let purchaserData = eventData.marketplace_purchase;
42+
const oAuthUrl = `${OAUTH_ENDPOINT}/authorize?client_id=${process.env.CLIENT_ID}&redirect_uri=${process.env.REDIRECT_URI}&state=${process.env.STATE}&login=${purchaserData.account.login}`;
43+
res.redirect(oAuthUrl);
44+
}
45+
};

controllers/pullRequest.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { listCommitsOfPullRequest, getPullRequest } = require('../helpers/pullReq
1111
* Constants
1212
*/
1313
const constants = require('../constants.js');
14+
const rp = require('request-promise');
1415
const mergeCommitRegex = constants.REGEX.MERGE_COMMIT_REGEX;
1516
const conclusionStatus = constants.conclusion_status;
1617
const messages = constants.messages;
@@ -29,8 +30,28 @@ const outputTitleFail = constants.output_title_fail;
2930
*/
3031
module.exports.commitAndTitleValidator = async (app, context, configuration, updateCheckRunFlag, createCheckRunFlag) => {
3132
try {
32-
let { prTitleRegex, commitTitleRegex } = regexExtractor(configuration);
33+
console.log('config received using single file:', configuration)
3334
let { owner, repository, pullRequestTitle, pullNumber } = prDetailsExtractor(context);
35+
36+
if (!configuration || !configuration.PR_TITLE_REGEX || !configuration.COMMIT_MESSAGE_REGEX) {
37+
let path = process.env.REGEX_CONFIG_FILE_PATH + '/' + process.env.REGEX_CONFIG_FILE_NAME;
38+
let configFile = await context.github.repos.getContents({owner:owner, repo: repository, path: path});
39+
let rpOptions = {
40+
uri: configFile.data.download_url,
41+
method: 'GET',
42+
};
43+
let fileData = await rp (rpOptions);
44+
let configArr = fileData.split("\n");
45+
configuration = {};
46+
let prTitleKey = configArr[0].substring(0, configArr[0].indexOf(':'));
47+
let prTitleValue = configArr[0].substring(configArr[0].indexOf(':') +1, configArr[0].length);
48+
configuration[prTitleKey.trim()] = prTitleValue.trim();
49+
let commitMsgKey = configArr[1].substring(0, configArr[1].indexOf(':'));
50+
let commitMsgValue = configArr[1].substring(configArr[1].indexOf(':') +1, configArr[1].length);
51+
configuration[commitMsgKey.trim()] = commitMsgValue.trim();
52+
console.log('config updated from new method:', configuration)
53+
}
54+
let { prTitleRegex, commitTitleRegex } = regexExtractor(configuration);
3455
/**
3556
* Find all commits for a pull request
3657
*/
@@ -54,6 +75,7 @@ module.exports.commitAndTitleValidator = async (app, context, configuration, upd
5475
let result = checkMessagesFormat(pullRequestTitle, commits.data, prTitleRegex, commitTitleRegex);
5576
await createOrUpdateCheckRun(context, owner, repository, result, updateCheckRunFlag, createCheckRunFlag);
5677
} catch (error) {
78+
console.log('------error------', error);
5779
app.log(error);
5880
}
5981
};

0 commit comments

Comments
 (0)