Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listagem das branchs e git checkout adicionado #222

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion html/configuracao/atualizacao.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"./debug_info.php"
]);

$redirect = $_GET["redirect"] ?? REDIRECT[0];
$redirect = $_GET["redirect"] ?? REDIRECT[1];

function tempBackup() {
if (PHP_OS != 'Linux'){
Expand Down
104 changes: 101 additions & 3 deletions html/configuracao/debug_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,57 @@
}
$conexao = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Função para obter as branches de um repositório no GitHub usando a API
function getGitHubBranches($owner, $repo)
{
$url = "https://api.github.com/repos/$owner/$repo/branches";
$options = [
'http' => [
'header' => "User-Agent: My-App\r\n",
],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
return json_decode($response, true);
}

function getCurrentBranch() {
$output = array();
exec("git -C ".ROOT." branch | grep '*' | cut -d ' ' -f2", $output);
return $output[0];
}

// Função para fazer o checkout para uma branch
function gitCheckout($branch) {
$output = array();
exec("git -C ".ROOT." checkout $branch", $output);
return $output;
}

// Obtém as branches do repositório
$owner = "nilsonLazarin";
$repo = "WeGIA";
$branches = [];
try {
$branchesData = getGitHubBranches($owner, $repo);
foreach ($branchesData as $branch) {
$branches[] = $branch['name'];
}
} catch (Exception $e) {
echo "Erro ao obter as branches do GitHub: " . $e->getMessage();
}


if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['branch'])) {
$branch = $_POST['branch'];
$action = $_POST["action"];

if ($action == "switch") {
$output = gitCheckout($branch);
} elseif ($action == "update") {
header("Location: atualizacao.php?branch=$branch");
}
}

// Verifica Permissão do Usuário
require_once '../permissao/permissao.php';
Expand Down Expand Up @@ -110,6 +160,44 @@
.btn{
width: 10%;
}

.config-item {
margin: 20px 0;
}

.config-item form {
display: flex;
align-items: center;
}

.config-item label,
.config-item select,
.config-item button {
margin: 0 10px;
}

.config-item button {
background-color: #4CAF50; /* Verde */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
transition-duration: 0.4s;
cursor: pointer;

border-radius: 12px;

width: 150px;
}

.config-item button:hover {
background-color: #45a049;

transform: scale(1.1);
}
</style>

</head>
Expand Down Expand Up @@ -192,9 +280,19 @@
?></p>
</div>
<div>
<div class="config-item">
<div>Atualizar sistema para versão em desenvolvimento:</div>
<button id="btn2" class="btn btn-warning" onClick="setLoader(this)"><a href="./atualizacao.php?redirect=./debug_info.php"><i class="fas fa-download" aria-hidden="true"></i></a></button>
<div class="config-item">
<div>Atualizar sistema para versão em desenvolvimento:</div>
<form action="debug_info.php" method="post">
<label for="branch">Escolha a branch para atualizar:</label>
<select name="branch" id="branch">
<?php foreach ($branches as $branch): ?>
<option value="<?php echo $branch; ?>" <?php if ($branch == getCurrentBranch()) echo 'style="color: #32CD32;"'; ?>><?php echo $branch; ?></option>
<?php endforeach; ?>
</select>
<button type="submit" name="action" value="switch">Trocar branch</button>
<button type="submit" name="action" value="update">Atualizar</button>
</form>
</div>
</div>
</div>

Expand Down