-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Nr18/develop
chore: create release
- Loading branch information
Showing
17 changed files
with
734 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,4 @@ __pycache__ | |
*.egg-info | ||
dist | ||
.coverage | ||
sample-reports/*.xml | ||
rules | ||
tests/rules/ | ||
/my-repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
|
||
REPOSITORY=my-repo | ||
|
||
set -e | ||
|
||
rm -rf "${REPOSITORY}" | ||
mkdir "${REPOSITORY}" | ||
pushd "${REPOSITORY}" | ||
touch README.md | ||
git init | ||
git remote add origin codecommit::eu-west-1://my-profile@repository | ||
git add README.md | ||
git commit -m "feat: initial commit" | ||
|
||
git checkout -b documentation-update | ||
|
||
echo "# ${REPOSITORY}" >> README.md | ||
echo "" >> README.md | ||
echo "This is a test repository with multiple commits. These commits can be used to test the pull-request-codecommit tool." >> README.md | ||
git add README.md | ||
git commit -m "feat: initial README setup | ||
Because it is a good practice to describe what a repository is doing we add it to the README.md. | ||
Issue: #1" | ||
|
||
echo "" >> README.md | ||
echo "We want to support multiple commits" >> README.md | ||
|
||
git add README.md | ||
git commit -m "docs: describe multiple commits | ||
Issue: #1" | ||
|
||
echo "" >> README.md | ||
echo "Even more and different issue number" >> README.md | ||
|
||
git add README.md | ||
git commit -m "chore: other issue number | ||
Issue: #2" | ||
|
||
echo "" >> README.md | ||
echo "Even more and different style issue number" >> README.md | ||
|
||
git add README.md | ||
git commit -m "refactor: use jira style issue number | ||
fixes issue JIRA-1234" | ||
|
||
poetry run pull-request-codecommit |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .client import Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import List | ||
import subprocess | ||
|
||
|
||
class Client: | ||
""" | ||
Understands aws operations | ||
We use the AWS CLI for these operations so that we can use tha MFA toke cache from the cli. | ||
""" | ||
|
||
def __init__(self, profile: str, region: str) -> None: | ||
self.__profile = profile | ||
self.__region = region | ||
|
||
def __execute(self, parameters: List[str]) -> str: | ||
command = ["aws", "--profile", self.__profile, "--region", self.__region] | ||
command.extend(parameters) | ||
response = subprocess.run(command, stdout=subprocess.PIPE) | ||
|
||
return response.stdout.decode("utf-8").strip("\n") | ||
|
||
def create_pull_request( | ||
self, | ||
title: str, | ||
description: str, | ||
repository: str, | ||
source: str, | ||
destination: str, | ||
) -> dict: | ||
command = [ | ||
"codecommit", | ||
"create-pull-request", | ||
"--title", | ||
title, | ||
"--description", | ||
description, | ||
"--targets", | ||
f"repositoryName={repository}, sourceReference={source}, destinationReference={destination}", | ||
] | ||
response = self.__execute(command) | ||
data = json.loads(response) | ||
return data.get("pullRequest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Dict, Optional | ||
|
||
import configparser | ||
from pathlib import Path | ||
|
||
|
||
class Config: | ||
""" | ||
Understands the configuration of the pull-request-codecommit tool. | ||
""" | ||
|
||
__cached_config: Dict[str, Dict[str, str]] = {} | ||
__config_file: Optional[configparser.ConfigParser] = None | ||
|
||
@classmethod | ||
def __default_config(cls) -> Dict[str, str]: | ||
return cls.__load_config("default") | ||
|
||
@classmethod | ||
def __get_config_value(cls, profile: str, key: str) -> str: | ||
if profile not in cls.__cached_config: | ||
cls.__cached_config[profile] = cls.__default_config() | ||
cls.__cached_config[profile].update(cls.__load_config(profile)) | ||
|
||
return cls.__cached_config[profile].get(key, "") | ||
|
||
@classmethod | ||
def __user_config(cls) -> configparser.ConfigParser: | ||
if not cls.__config_file: | ||
cls.__config_file = configparser.ConfigParser() | ||
cls.__config_file.read(f"{Path.home()}/.aws/pull-request-codecommit") | ||
|
||
return cls.__config_file | ||
|
||
@classmethod | ||
def __load_config(cls, profile: str) -> Dict[str, str]: | ||
config = {} | ||
|
||
if profile != "default": | ||
profile = f"profile {profile}" | ||
|
||
if profile in cls.__user_config().sections(): | ||
for key, value in list(cls.__user_config().items(profile)): | ||
config[key] = value | ||
|
||
return config | ||
|
||
@classmethod | ||
def destination_branch(cls, profile: str) -> str: | ||
return cls.__get_config_value(profile, "branch") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .commits import Commits | ||
from .commit import Commit | ||
from .message import Message | ||
from .client import Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
from typing import List | ||
import os.path | ||
import subprocess | ||
from .commits import Commits | ||
|
||
|
||
class Client: | ||
""" | ||
Understands git operations | ||
""" | ||
|
||
def __init__(self, path: str): | ||
if not os.path.isdir(path): | ||
raise NotADirectoryError(f"The {path} is not a directory.") | ||
|
||
self.__path: str = path | ||
|
||
def __execute(self, parameters: List[str]) -> str: | ||
parameters.insert(0, "git") | ||
response = subprocess.run(parameters, cwd=self.__path, stdout=subprocess.PIPE) | ||
|
||
return response.stdout.decode("utf-8").strip("\n") | ||
|
||
def remote(self, name: str = "origin") -> str: | ||
return self.__execute(["config", "--get", f"remote.{name}.url"]) | ||
|
||
@property | ||
def current_branch(self) -> str: | ||
return self.__execute(["branch", "--show-current"]) | ||
|
||
def get_commit_messages(self, destination_branch: str) -> Commits: | ||
messages = self.__execute( | ||
["log", f"{destination_branch}..{self.current_branch}"] | ||
) | ||
|
||
return Commits(messages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from .message import Message | ||
|
||
|
||
class Commit: | ||
""" | ||
Understands git commit | ||
""" | ||
|
||
def __init__(self, commit: str, author: str, date: str, message: Message) -> None: | ||
self.__commit: str = commit | ||
self.__author: str = author | ||
self.__date: str = date | ||
self.__message: Message = message | ||
|
||
@property | ||
def message(self) -> Message: | ||
return self.__message |
Oops, something went wrong.