在Github上开发一个大型开源存储库。有超过300个拉取请求(PR)等待队列合并到主分支。
我想在文件中添加功能,在此之前,我需要确保没有存在的PR进行相同的更改。
那么如何找出包含特定文件更改的拉取请求?
答案 0 :(得分:1)
您可以尝试获取本地存储库中的所有PR分支,然后搜索修改文件的提交。
做到这一点,做:
将项目存储库添加为upstream
遥控器。
git remote add upstream https://github.com/[orga]/[project].git
打开.git\config
文件,将行fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
添加到[upstream]
部分。它应该看起来像这样:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://github.com/[orga]/[project].git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
执行将获取所有遥控器的git fetch --all
搜索所需文件的更新:
List all commits (across all branches) for a given file
甚至更好地满足您的需求...
答案 1 :(得分:0)
从@Philippe和@ knight9631获得帮助,我得到了期望的结果。
按照@ Philippe的回复中所述进行public class EditorFrame extends JFrame {
/**
* @field serialVersionUID
*/
private static final long serialVersionUID = 1L;
private JTextArea textArea;
private JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
public static void main(String[] args) {
EditorFrame frame = new EditorFrame();
frame.init();
}
private void init(){
this.setSize(640, 480);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Editor");
this.setContentPane(createContentPanel());
this.setVisible(true);
}
/**
* @return
* @return Container
*/
private Container createContentPanel() {
JPanel jPanel = new JPanel(new BorderLayout());
textArea = new JTextArea();
jPanel.add(textArea,BorderLayout.CENTER);
jPanel.add(createButton(),BorderLayout.NORTH);
return jPanel;
}
/**
* @return
* @return Component
*/
private Component createButton() {
JPanel jPanel = new JPanel(new GridLayout(1, 2));
JButton openButton = new JButton("Open");
JButton saveButton = new JButton("Save");
jPanel.add(openButton);
jPanel.add(saveButton);
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int state = jfc.showOpenDialog(null);
if (state == 0) {
File f = jfc.getSelectedFile();
try {
String textString = readText(new FileInputStream(f), "utf-8");
textArea.setText(textString);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
});
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
writeText(textArea.getText(),jfc.getSelectedFile().getAbsolutePath());
}
});
return jPanel;
}
private String readText(final InputStream in, String charset) {
if (charset == null) {
charset = Charset.defaultCharset().toString();
}
StringBuffer text = new StringBuffer();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(in, charset));
String line = null;
while ((line = br.readLine()) != null) {
text.append(line + "\n");
}
br.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return text.toString();
}
private void writeText(final String text, final String descPath) {
File root = new File(descPath.substring(0, descPath.lastIndexOf('\\')));
if (!root.exists()) {
root.mkdirs();
}
try {
// BufferedWriter bw = new BufferedWriter(new
// FileWriter(descPath));
BufferedWriter bw =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(descPath), Charset.forName("UTF-8")));
bw.write(text);
bw.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
更改。
upstream
运行以下脚本。
$ git remote add upstream https://github.com/[orga]/[project].git
# add fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to .git/config in session origin
$ git fetch --all
FILENAME=$1
git log --all --format=%d $FILENAME|awk -F "[\/|\)]" '/pr/{print $3}' |sort -n |while read line
do
state=$(curl -s https://api.github.com/repos/ansible/ansible/pulls/$line|jq -r .state)
if [[ $state == "open" ]]; then
echo "PR $line hasn't been merged"
fi
done
获取Github API时需要添加授权令牌。否则,您将轻松点击rate-limiting
$ bash PR.sh abc.json
PR 22857 hasn't been merged
PR 19231 hasn't been merged
PR 22981 hasn't been merged